PNA.fi koodi

sodexo.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import pnalib
  2. import datetime
  3. restaurant_info = [
  4. [ "(TaY) Sodexo Linna", "http://www.sodexo.fi/linna", "", "right", 92],
  5. #[ "(TTY) Sodexo Erkkeri", "http://www.sodexo.fi/erkkeri", "", "left", 100]
  6. [ "(TTY) Sodexo Hertsi", "http://www.sodexo.fi/tty-tietotalo", "", "right", 12812]
  7. ]
  8. def get_restaurants(use_old, week):
  9. restaurants = []
  10. for count, info in enumerate(restaurant_info):
  11. kitchen = info[4]
  12. title = info[0]
  13. open_hours = ""
  14. week_foods = {}
  15. today = datetime.date.today()
  16. week_day = today.isocalendar()[2]
  17. last_sunday = today - datetime.timedelta(days=week_day)
  18. for weekday in range(1,7):
  19. date = last_sunday + datetime.timedelta(days=weekday)
  20. timestr = date.strftime("%Y/%m/%d")
  21. url = "http://www.sodexo.fi/ruokalistat/output/daily_json/{kitchen}/{timestr}/fi".format(kitchen=kitchen, timestr=timestr)
  22. temp_fname = "sodexo_{count}-{weekday}.temp.js".format(count=count, weekday=weekday)
  23. data = pnalib.get_json_file(url, temp_fname, use_old)
  24. if not data:
  25. continue
  26. current_day_foods = []
  27. courses = data["courses"]
  28. for course_info in courses:
  29. if course_info["category"] != "Aamupuuro":
  30. food = course_info["title_fi"]
  31. if "properties" in course_info:
  32. food += " ({allergies})".format(allergies=course_info["properties"])
  33. current_day_foods.append(food)
  34. week_foods[weekday-1] = current_day_foods
  35. restaurants.append([title, open_hours, week, week_foods, info])
  36. return restaurants