PNA.fi koodi

juvenes.py 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # encoding: UTF-8
  2. import pnalib
  3. import datetime
  4. import re
  5. import json
  6. # Last three columns are Kitchen Info ID, Menu Type ID and Concept ID. There may be multiple concepts in a single restauranta.
  7. # Juvenes API defines also Restaurant ID but that is not used.
  8. restaurant_info = [
  9. [ "(TaY) Yliopiston Ravintola",
  10. "https://www.juvenes.fi/yoravintola",
  11. "M", "left", 13, 60, []],
  12. [ "(TaY) Yliopiston Ravintola / VegeBar",
  13. "https://www.juvenes.fi/yoravintola",
  14. "", "left", 13, 5, []],
  15. [ "(TaY) Café Alakuppila (Paniini & Combosalaatti)",
  16. "https://www.juvenes.fi/alakuppila",
  17. "", "left", 130018, 58, []],
  18. [ "(TaY) Café Pinni",
  19. "https://www.juvenes.fi/pinni",
  20. "M", "middle", 130016, 60, []],
  21. [ "(TAYS) Arvo",
  22. "https://www.juvenes.fi/arvo",
  23. "M", "left", 5, 60, []],
  24. [ "(TAYS) Café Lea (Fusion Kitchen)",
  25. "https://www.juvenes.fi/lea",
  26. "M", "left", 50026, 3, []],
  27. # [ "(TAYS) Café Lea (My Salad)",
  28. # "https://www.juvenes.fi/lea",
  29. # "M", "left", 50026, 76, []],
  30. [ "(TTY) Newton",
  31. "https://www.juvenes.fi/newton",
  32. "", "left", 6, 60, [1149]],
  33. [ "(TTY) Café Konehuone / Såås bar",
  34. "https://www.juvenes.fi/konehuone",
  35. "", "left", 60038, 77, [3663]],
  36. [ "(TTY) Café Konehuone / Fusion Kitchen",
  37. "https://www.juvenes.fi/konehuone",
  38. "", "middle", 60038, 3, [1674]],
  39. [ "(TAMK) Ziberia (Koto my plate)",
  40. "https://www.juvenes.fi/ziberia",
  41. "", "middle", 11, 82, []],
  42. [ "(TAMK) Ziberia (Koto)",
  43. "https://www.juvenes.fi/ziberia",
  44. "", "middle", 11, 79, []],
  45. [ "(TAMK) Ziberia (My Salad)",
  46. "https://www.juvenes.fi/ziberia",
  47. "", "middle", 11, 76, []],
  48. [ "(TAMK) Frenckell / Koto",
  49. "https://www.juvenes.fi/frenckell",
  50. "", "middle", 33, 60, []],
  51. [ "(TAMK) Frenckell / Iltapäivälounas",
  52. "https://www.juvenes.fi/frenckell",
  53. "", "middle", 33, 85, []]
  54. ]
  55. def get_restaurants(use_old, week):
  56. restaurants = []
  57. for count, info in enumerate(restaurant_info):
  58. kitchen = info[4]
  59. menutype = info[5]
  60. concepts = info[6]
  61. title = info[0]
  62. cur_title = title
  63. open_hours = ""
  64. exception = None
  65. week_foods = {}
  66. for weekday in range(1,7):
  67. url = "http://www.juvenes.fi/DesktopModules/Talents.LunchMenu/LunchMenuServices.asmx/GetMenuByWeekday?KitchenId={kitchen}&MenuTypeId={menutype}&Week={week}&Weekday={weekday}&lang='fi'&format=json".format(kitchen=kitchen, menutype=menutype, week=week, weekday=weekday)
  68. temp_fname = "juvenes_{count}-{weekday}.temp.js".format(count=count, weekday=weekday)
  69. data = pnalib.get_json_file(url, temp_fname, use_old, allow_old=False)
  70. if not data:
  71. # Try to find problem
  72. for concept in concepts:
  73. url = "http://www.juvenes.fi/DesktopModules/Talents.Restaurants/RestaurantsService.svc/GetConcept?menuId={concept}&lang=fi".format(concept=concept)
  74. temp_fname = "juvenes_{count}-{weekday}-{concept}.temp.js".format(count=count, weekday=weekday, concept=concept)
  75. data = pnalib.get_json_file(url, temp_fname, use_old, allow_old=False)
  76. if data and data["d"]:
  77. exception = data["d"]["OpenInfo"]["Exeption1InfoText"]
  78. elif data and data["d"] != "null":
  79. data = json.loads(data["d"])
  80. cur_day_foods = []
  81. mealoptions = data["MealOptions"]
  82. for meal_info in mealoptions:
  83. cur_food = []
  84. if "ForceMajoure" in meal_info and meal_info["ForceMajoure"] != "":
  85. cur_food = [meal_info["ForceMajoure"]]
  86. else:
  87. menuitems = meal_info["MenuItems"]
  88. for food_info in menuitems:
  89. name = food_info["Name"]
  90. name = re.sub(r"^\*", "", name)
  91. if food_info["Diets"]:
  92. cur_food.append("{name} ({diets})".format(name=name, diets=food_info["Diets"]))
  93. elif name:
  94. cur_food.append(name)
  95. if cur_food != ["-"]:
  96. cur_day_foods.append("\n".join(cur_food))
  97. week_foods[weekday-1] = cur_day_foods
  98. restaurants.append([title, open_hours, week, week_foods, info, exception])
  99. return restaurants