# encoding: UTF-8 # Copyright 2018 Toni Fadjukoff. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import pnalib import datetime import re import json # Last three columns are Kitchen Info ID, Menu Type ID and Concept ID. There may be multiple concepts in a single restauranta. # Juvenes API defines also Restaurant ID but that is not used. restaurant_info = [ [ "(TaY) Yliopiston Ravintola", "https://www.juvenes.fi/yoravintola", "M", "left", 13, 60, []], [ "(TaY) Yliopiston Ravintola / VegeBar", "https://www.juvenes.fi/yoravintola", "", "left", 13, 5, []], [ "(TaY) Café Alakuppila (Paniini & Combosalaatti)", "https://www.juvenes.fi/alakuppila", "", "left", 130018, 58, []], [ "(TaY) Café Pinni", "https://www.juvenes.fi/pinni", "M", "middle", 130016, 60, []], [ "(TAYS) Arvo", "https://www.juvenes.fi/arvo", "M", "left", 5, 60, []], [ "(TAYS) Café Lea (Fusion Kitchen)", "https://www.juvenes.fi/lea", "M", "left", 50026, 3, []], # [ "(TAYS) Café Lea (My Salad)", # "https://www.juvenes.fi/lea", # "M", "left", 50026, 76, []], [ "(TTY) Newton", "https://www.juvenes.fi/newton", "", "left", 6, 60, [1149]], [ "(TTY) Café Konehuone / Såås bar", "https://www.juvenes.fi/konehuone", "", "left", 60038, 77, [3663]], [ "(TTY) Café Konehuone / Fusion Kitchen", "https://www.juvenes.fi/konehuone", "", "middle", 60038, 3, [1674]], [ "(TAMK) Ziberia (Koto my plate)", "https://www.juvenes.fi/ziberia", "", "middle", 11, 82, []], [ "(TAMK) Ziberia (Koto)", "https://www.juvenes.fi/ziberia", "", "middle", 11, 79, []], [ "(TAMK) Ziberia (My Salad)", "https://www.juvenes.fi/ziberia", "", "middle", 11, 76, []], [ "(TAMK) Frenckell / Koto", "https://www.juvenes.fi/frenckell", "", "middle", 33, 60, []], [ "(TAMK) Frenckell / Iltapäivälounas", "https://www.juvenes.fi/frenckell", "", "middle", 33, 85, []] ] def get_restaurants(use_old, week): restaurants = [] for count, info in enumerate(restaurant_info): kitchen = info[4] menutype = info[5] concepts = info[6] title = info[0] cur_title = title open_hours = "" exception = None week_foods = {} for weekday in range(1,7): 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) temp_fname = "juvenes_{count}-{weekday}.temp.js".format(count=count, weekday=weekday) data = pnalib.get_json_file(url, temp_fname, use_old, allow_old=False) if not data: # Try to find problem for concept in concepts: url = "http://www.juvenes.fi/DesktopModules/Talents.Restaurants/RestaurantsService.svc/GetConcept?menuId={concept}&lang=fi".format(concept=concept) temp_fname = "juvenes_{count}-{weekday}-{concept}.temp.js".format(count=count, weekday=weekday, concept=concept) data = pnalib.get_json_file(url, temp_fname, use_old, allow_old=False) if data and data["d"]: exception = data["d"]["OpenInfo"]["Exeption1InfoText"] elif data and data["d"] != "null": data = json.loads(data["d"]) cur_day_foods = [] mealoptions = data["MealOptions"] for meal_info in mealoptions: cur_food = [] if "ForceMajoure" in meal_info and meal_info["ForceMajoure"] != "": cur_food = [meal_info["ForceMajoure"]] else: menuitems = meal_info["MenuItems"] for food_info in menuitems: name = food_info["Name"] name = re.sub(r"^\*", "", name) if food_info["Diets"]: cur_food.append("{name} ({diets})".format(name=name, diets=food_info["Diets"])) elif name: cur_food.append(name) if cur_food != ["-"]: cur_day_foods.append("\n".join(cur_food)) week_foods[weekday-1] = cur_day_foods restaurants.append([title, open_hours, week, week_foods, info, exception]) return restaurants