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

import datetime
from telegram import ParseMode
import requests
DISABLED_GROUPS = [-1001301570558]
DIETS = {
"veggy": "fleischlos",
"fleisch": "mit Fleisch",
"fisch": "mit Fisch/Meeresfrüchten"
}
WEEKDAYS = {
"montag": 1,
"dienstag": 2,
"mittwoch": 3,
"donnerstag": 4,
"freitag": 5,
"samstag": 6,
}
MENSA_URL = {
"zentral": "goe1",
"turm": "goe2",
"nord": "goe3",
"italia": "goe4",
"fasthochschule": "goe5"
}
MENSA_NAME = {
"zentral": "Zentralmensa",
"nord": "Nordmensa",
"turm": "Turmmensa",
"italia": "Mensa Italia",
"fasthochschule": "Bistro Fasthochschule"
}
HIDE_CATEGORIES_LIGHT = {
"CampusCurry",
"natürlich fit",
"Fitnesscenter",
"Salatbuffet",
"Studentenfutter",
"Süße Versuchung",
"Süße Spezial Tagesangebot",
"Vollwert & Co. Stärke",
"Vollwert & Co. Gemüse",
"Bio-Beilagen",
"Dessertbuffet",
"Last Minute ab 14:30 Uhr",
## Nordmensa:
"Salatbuffet/Pastapoint",
"Last Minute ab 13:30 Uhr",
## Turmmensa:
"Beilagen",
"Last Minute ab 14:00Uhr"
}
HIDE_CATEGORIES_FULL = {
"Last Minute ab 14:30 Uhr",
"Last Minute ab 13:30 Uhr",
"Last Minute ab 14:00Uhr"
}
MODES = {
"light": HIDE_CATEGORIES_LIGHT,
"full": HIDE_CATEGORIES_FULL
}
def mensa(bot, update, args):
if update.message.chat_id in DISABLED_GROUPS:
return
which = "zentral"
filter_categories = MODES["light"]
today = datetime.datetime.now().date()
if datetime.datetime.now().time() > datetime.time(hour=16):
today += datetime.timedelta(days=1)
for arg in args:
arg = arg.lower()
if arg in MENSA_NAME:
which = arg
elif arg in MODES:
filter_categories = MODES[arg]
elif arg in WEEKDAYS:
today = WEEKDAYS[arg]
# elif arg in DIETS:
# diet = DIETS[arg]
else:
update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.")
return
# if today == 0:
# update.message.reply_text("Sonntags hat die Mensa zu")
# return
url = "https://app.mensaplan.de/api/11102/de.mensaplan.app.android.goettingen/%s.json" % MENSA_URL[which]
request = requests.get(url)
request.encoding = 'utf-8'
data = request.json()
today_data = get_data_for_day(today, data)
message = "Das Essen für %s in der %s \n\n" % (today_data["date"], MENSA_NAME[which])
for cat in today_data['categories']:
if cat['name'] not in filter_categories:
meal_line = "*%s*\n" % cat['name']
for meal in cat['meals']:
meal_line += meal['name'].strip() + "\n"
message += meal_line + '\n'
update.message.reply_text(message, ParseMode.MARKDOWN)
def get_data_for_day(day, complete_data):
for date in complete_data['days']:
if day.isoformat() == date['iso-date']:
return date