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.

126 lines
3.2 KiB

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