PNA.fi koodi

juvenes.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # encoding: UTF-8
  2. import pnalib
  3. import datetime
  4. import re
  5. import json
  6. # last two in order are $kitchen_info_id, $menu_type_id
  7. restaurant_info = [
  8. [ "(TaY) Yliopiston Ravintola", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/yliopistonravintola.aspx", "M", "left", 13, 60 ],
  9. [ "(TaY) Yliopiston Ravintola / VegeBar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/yliopistonravintola.aspx", "", "left", 13, 5 ],
  10. [ "(TaY) Café Campus", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/caf%C3%A9campus.aspx", "", "left", 130019, 23 ],
  11. [ "(TaY) Café Pinni", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/caf%C3%A9lunchpinni.aspx", "M", "middle", 130016, 60 ],
  12. [ "(TAYS) Arvo", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/arvo.aspx", "M", "left", 5, 60 ],
  13. [ "(TAYS) Café Lea (Fusion Kitchen)", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/cafélea.aspx", "M", "left", 50026, 3 ],
  14. [ "(TAYS) Café Lea (My Salad)", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/cafélea.aspx", "M", "left", 50026, 76 ],
  15. [ "(TTY) Newton", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/newton.aspx", "", "left", 6, 60],
  16. [ "(TTY) Café Konehuone / Såås bar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/caf%C3%A9konehuone/s%C3%A5%C3%A5sbar.aspx", "", "left", 60038, 77],
  17. [ "(TTY) Café Konehuone / Fusion Kitchen", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/caf%C3%A9konehuone/fusionkitchen.aspx", "", "middle", 60038, 3 ],
  18. [ "(TAMK) Ziberia", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/ziberia.aspx", "", "middle", 11, 60 ],
  19. # [ "(TAMK) Frenckell", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/frenckell.aspx", "", "middle", 33, 60 ],
  20. [ "(TAMK) Frenckell / Såås bar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/frenckell.aspx", "", "middle", 33, 77 ]
  21. ]
  22. def get_restaurants(use_old, week):
  23. restaurants = []
  24. for count, info in enumerate(restaurant_info):
  25. kitchen = info[4]
  26. menutype = info[5]
  27. title = info[0]
  28. cur_title = title
  29. open_hours = ""
  30. week_foods = {}
  31. for weekday in range(1,7):
  32. 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)
  33. temp_fname = "juvenes_{count}-{weekday}.temp.js".format(count=count, weekday=weekday)
  34. data = pnalib.get_jsonp_file(url, temp_fname, use_old)
  35. if data and data["d"] != "null":
  36. data = json.loads(data["d"])
  37. cur_day_foods = []
  38. mealoptions = data["MealOptions"]
  39. for meal_info in mealoptions:
  40. cur_food = []
  41. if "ForceMajoure" in meal_info and meal_info["ForceMajoure"] != "":
  42. cur_food = [meal_info["ForceMajoure"]]
  43. else:
  44. menuitems = meal_info["MenuItems"]
  45. for food_info in menuitems:
  46. name = food_info["Name"]
  47. name = re.sub(r"^\*", "", name)
  48. if food_info["Diets"]:
  49. cur_food.append("{name} ({diets})".format(name=name, diets=food_info["Diets"]))
  50. elif name:
  51. cur_food.append(name)
  52. if cur_food != ["-"]:
  53. cur_day_foods.append("\n".join(cur_food))
  54. week_foods[weekday-1] = cur_day_foods
  55. restaurants.append([title, open_hours, week, week_foods, info])
  56. return restaurants