PNA.fi koodi

juvenes.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 / Såås bar",
  49. "https://www.juvenes.fi/frenckell",
  50. "", "middle", 33, 77, []]
  51. ]
  52. def get_restaurants(use_old, week):
  53. restaurants = []
  54. for count, info in enumerate(restaurant_info):
  55. kitchen = info[4]
  56. menutype = info[5]
  57. concepts = info[6]
  58. title = info[0]
  59. cur_title = title
  60. open_hours = ""
  61. exception = None
  62. week_foods = {}
  63. for weekday in range(1,7):
  64. 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)
  65. temp_fname = "juvenes_{count}-{weekday}.temp.js".format(count=count, weekday=weekday)
  66. data = pnalib.get_json_file(url, temp_fname, use_old, allow_old=False)
  67. if not data:
  68. # Try to find problem
  69. for concept in concepts:
  70. url = "http://www.juvenes.fi/DesktopModules/Talents.Restaurants/RestaurantsService.svc/GetConcept?menuId={concept}&lang=fi".format(concept=concept)
  71. temp_fname = "juvenes_{count}-{weekday}-{concept}.temp.js".format(count=count, weekday=weekday, concept=concept)
  72. data = pnalib.get_json_file(url, temp_fname, use_old, allow_old=False)
  73. if data and data["d"]:
  74. exception = data["d"]["OpenInfo"]["Exeption1InfoText"]
  75. elif data and data["d"] != "null":
  76. data = json.loads(data["d"])
  77. cur_day_foods = []
  78. mealoptions = data["MealOptions"]
  79. for meal_info in mealoptions:
  80. cur_food = []
  81. if "ForceMajoure" in meal_info and meal_info["ForceMajoure"] != "":
  82. cur_food = [meal_info["ForceMajoure"]]
  83. else:
  84. menuitems = meal_info["MenuItems"]
  85. for food_info in menuitems:
  86. name = food_info["Name"]
  87. name = re.sub(r"^\*", "", name)
  88. if food_info["Diets"]:
  89. cur_food.append("{name} ({diets})".format(name=name, diets=food_info["Diets"]))
  90. elif name:
  91. cur_food.append(name)
  92. if cur_food != ["-"]:
  93. cur_day_foods.append("\n".join(cur_food))
  94. week_foods[weekday-1] = cur_day_foods
  95. restaurants.append([title, open_hours, week, week_foods, info, exception])
  96. return restaurants