Telegram version of schneiderbot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. import datetime
  2. from telegram import ParseMode
  3. import requests
  4. DIETS = {
  5. "veggy": "fleischlos",
  6. "fleisch": "mit Fleisch",
  7. "fisch": "mit Fisch/Meeresfrüchten"
  8. }
  9. WEEKDAYS = {
  10. "montag": 1,
  11. "dienstag": 2,
  12. "mittwoch": 3,
  13. "donnerstag": 4,
  14. "freitag": 5,
  15. "samstag": 6,
  16. }
  17. MENSA_URL = {
  18. "zentral": "goe1",
  19. "turm": "goe2",
  20. "nord": "goe3",
  21. "italia": "goe4",
  22. "fasthochschule": "goe5"
  23. }
  24. MENSA_NAME = {
  25. "zentral": "Zentralmensa",
  26. "nord": "Nordmensa",
  27. "turm": "Turmmensa",
  28. "italia": "Mensa Italia",
  29. "fasthochschule": "Bistro Fasthochschule"
  30. }
  31. HIDE_CATEGORIES_LIGHT = {
  32. "CampusCurry",
  33. "natürlich fit",
  34. "Fitnesscenter",
  35. "Salatbuffet",
  36. "Studentenfutter",
  37. "Süße Versuchung",
  38. "Süße Spezial Tagesangebot",
  39. "Vollwert & Co. Stärke",
  40. "Vollwert & Co. Gemüse",
  41. "Bio-Beilagen",
  42. "Dessertbuffet",
  43. "Last Minute ab 14:30 Uhr",
  44. ## Nordmensa:
  45. "Salatbuffet/Pastapoint",
  46. "Last Minute ab 13:30 Uhr",
  47. ## Turmmensa:
  48. "Beilagen",
  49. "Last Minute ab 14:00Uhr"
  50. }
  51. HIDE_CATEGORIES_FULL = {
  52. "Last Minute ab 14:30 Uhr",
  53. "Last Minute ab 13:30 Uhr",
  54. "Last Minute ab 14:00Uhr"
  55. }
  56. MODES = {
  57. "light": HIDE_CATEGORIES_LIGHT,
  58. "full": HIDE_CATEGORIES_FULL
  59. }
  60. def mensa(bot, update, args):
  61. which = "zentral"
  62. filter_categories = MODES["light"]
  63. today = datetime.datetime.now().date()
  64. if datetime.datetime.now().time() > datetime.time(hour=16):
  65. today += datetime.timedelta(days=1)
  66. for arg in args:
  67. arg = arg.lower()
  68. if arg in MENSA_NAME:
  69. which = arg
  70. elif arg in MODES:
  71. filter_categories = MODES[arg]
  72. elif arg in WEEKDAYS:
  73. today = WEEKDAYS[arg]
  74. # elif arg in DIETS:
  75. # diet = DIETS[arg]
  76. else:
  77. update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.")
  78. return
  79. # if today == 0:
  80. # update.message.reply_text("Sonntags hat die Mensa zu")
  81. # return
  82. url = "https://app.mensaplan.de/api/11102/de.mensaplan.app.android.goettingen/%s.json" % MENSA_URL[which]
  83. request = requests.get(url)
  84. request.encoding = 'utf-8'
  85. data = request.json()
  86. today_data = get_data_for_day(today, data)
  87. message = "Das Essen für %s in der %s \n\n" % (today_data["date"], MENSA_NAME[which])
  88. for cat in today_data['categories']:
  89. if cat['name'] not in filter_categories:
  90. meal_line = "*%s*\n" % cat['name']
  91. for meal in cat['meals']:
  92. meal_line += meal['name'].strip() + "\n"
  93. message += meal_line + '\n'
  94. update.message.reply_text(message, ParseMode.MARKDOWN)
  95. def get_data_for_day(day, complete_data):
  96. for date in complete_data['days']:
  97. if day.isoformat() == date['iso-date']:
  98. return date