PNA.fi koodi

sodexo.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright 2018 Toni Fadjukoff. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import pnalib
  15. import datetime
  16. restaurant_info = [
  17. [ "(TaY) Sodexo Linna", "http://www.sodexo.fi/linna", "", "right", 92],
  18. #[ "(TTY) Sodexo Erkkeri", "http://www.sodexo.fi/erkkeri", "", "left", 100]
  19. [ "(TTY) Sodexo Hertsi", "http://www.sodexo.fi/tty-tietotalo", "", "right", 12812]
  20. ]
  21. def get_restaurants(use_old, week):
  22. restaurants = []
  23. for count, info in enumerate(restaurant_info):
  24. kitchen = info[4]
  25. title = info[0]
  26. open_hours = ""
  27. week_foods = {}
  28. today = datetime.date.today()
  29. week_day = today.isocalendar()[2]
  30. last_sunday = today - datetime.timedelta(days=week_day)
  31. for weekday in range(1,7):
  32. date = last_sunday + datetime.timedelta(days=weekday)
  33. timestr = date.strftime("%Y/%m/%d")
  34. url = "http://www.sodexo.fi/ruokalistat/output/daily_json/{kitchen}/{timestr}/fi".format(kitchen=kitchen, timestr=timestr)
  35. temp_fname = "sodexo_{count}-{weekday}.temp.js".format(count=count, weekday=weekday)
  36. data = pnalib.get_json_file(url, temp_fname, use_old)
  37. if not data:
  38. continue
  39. current_day_foods = []
  40. courses = data["courses"]
  41. print(data)
  42. for course_info in courses:
  43. if not "category" in course_info or not "title_fi" in course_info or not "properties" in course_info:
  44. continue
  45. if course_info["category"] != "Aamupuuro":
  46. food = course_info["title_fi"]
  47. if "properties" in course_info:
  48. food += " ({allergies})".format(allergies=course_info["properties"])
  49. current_day_foods.append(food)
  50. week_foods[weekday-1] = current_day_foods
  51. restaurants.append([title, open_hours, week, week_foods, info])
  52. return restaurants