123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- # 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
-
- 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
|