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.

111 lines
2.7 KiB

  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. offset = 0
  64. # today = datetime.datetime.now().date().weekday() + 1
  65. if datetime.datetime.now().time() > datetime.time(hour=16):
  66. offset += 1
  67. #
  68. # today = today % 7
  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. today = WEEKDAYS[arg]
  77. # elif arg in DIETS:
  78. # diet = DIETS[arg]
  79. else:
  80. update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.")
  81. return
  82. # if today == 0:
  83. # update.message.reply_text("Sonntags hat die Mensa zu")
  84. # return
  85. url = "https://app.mensaplan.de/api/11102/de.mensaplan.app.android.goettingen/%s.json" % MENSA_URL[which]
  86. request = requests.get(url)
  87. request.encoding = 'utf-8'
  88. data = request.json()
  89. today_data = data['days'][offset]
  90. message = "Das Essen für %s in der %s \n\n" % (today_data["date"], MENSA_NAME[which])
  91. for cat in today_data['categories']:
  92. if cat['name'] not in filter_categories:
  93. meal_line = "*%s*\n" % cat['name']
  94. for meal in cat['meals']:
  95. meal_line += meal['name'].strip() + "\n"
  96. message += meal_line + '\n'
  97. update.message.reply_text(message, ParseMode.MARKDOWN)