import pnalib import datetime restaurant_info = [ [ "(TaY) Sodexo Linna", "http://www.sodexo.fi/linna", "", "right", 92], #[ "(TTY) Sodexo Erkkeri", "http://www.sodexo.fi/erkkeri", "", "left", 100] [ "(TTY) Sodexo Hertsi", "http://www.sodexo.fi/tty-tietotalo", "", "right", 12812] ] def get_restaurants(use_old, week): restaurants = [] for count, info in enumerate(restaurant_info): kitchen = info[4] title = info[0] open_hours = "" week_foods = {} today = datetime.date.today() week_day = today.isocalendar()[2] last_sunday = today - datetime.timedelta(days=week_day) for weekday in range(1,7): date = last_sunday + datetime.timedelta(days=weekday) timestr = date.strftime("%Y/%m/%d") url = "http://www.sodexo.fi/ruokalistat/output/daily_json/{kitchen}/{timestr}/fi".format(kitchen=kitchen, timestr=timestr) temp_fname = "sodexo_{count}-{weekday}.temp.js".format(count=count, weekday=weekday) data = pnalib.get_json_file(url, temp_fname, use_old) if not data: continue current_day_foods = [] courses = data["courses"] print(data) for course_info in courses: if not "category" in course_info or not "title_fi" in course_info or not "properties" in course_info: continue if course_info["category"] != "Aamupuuro": food = course_info["title_fi"] if "properties" in course_info: food += " ({allergies})".format(allergies=course_info["properties"]) current_day_foods.append(food) week_foods[weekday-1] = current_day_foods restaurants.append([title, open_hours, week, week_foods, info]) return restaurants