Telegram version of schneiderbot. I'll totally do something w/ this, this is never going to be effectively a mirror.
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.

117 lines
2.9 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. 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. }
  18. MENSA_URL = {
  19. "zentral": "goe1",
  20. "turm": "goe2",
  21. "nord": "goe3",
  22. "italia": "goe4",
  23. "fasthochschule": "goe5"
  24. }
  25. MENSA_NAME = {
  26. "zentral": "Zentralmensa",
  27. "nord": "Nordmensa",
  28. "turm": "Turmmensa",
  29. "italia": "Mensa Italia",
  30. "fasthochschule": "Bistro Fasthochschule"
  31. }
  32. HIDE_CATEGORIES_LIGHT = {
  33. "CampusCurry",
  34. "natürlich fit",
  35. "Fitnesscenter",
  36. "Salatbuffet",
  37. "Studentenfutter",
  38. "Süße Versuchung",
  39. "Süße Spezial Tagesangebot",
  40. "Vollwert & Co. Stärke",
  41. "Vollwert & Co. Gemüse",
  42. "Bio-Beilagen",
  43. "Dessertbuffet",
  44. "Last Minute ab 14:30 Uhr",
  45. ## Nordmensa:
  46. "Salatbuffet/Pastapoint",
  47. "Last Minute ab 13:30 Uhr",
  48. ## Turmmensa:
  49. "Beilagen",
  50. "Last Minute ab 14:00Uhr"
  51. }
  52. HIDE_CATEGORIES_FULL = {
  53. "Last Minute ab 14:30 Uhr",
  54. "Last Minute ab 13:30 Uhr",
  55. "Last Minute ab 14:00Uhr"
  56. }
  57. MODES = {
  58. "light": HIDE_CATEGORIES_LIGHT,
  59. "full": HIDE_CATEGORIES_FULL
  60. }
  61. def mensa(bot, update, args):
  62. if update.message.chat_id in DISABLED_GROUPS:
  63. return
  64. which = "zentral"
  65. filter_categories = MODES["light"]
  66. today = datetime.datetime.now().date()
  67. if datetime.datetime.now().time() > datetime.time(hour=16):
  68. today += datetime.timedelta(days=1)
  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 = get_data_for_day(today, data)
  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)
  98. def get_data_for_day(day, complete_data):
  99. for date in complete_data['days']:
  100. if day.isoformat() == date['iso-date']:
  101. return date