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.
 
 

131 lines
3.5 KiB

import datetime
from telegram import ParseMode
import requests
DISABLED_GROUPS = [-1001301570558]
DIETS = {
"veggy": ["Vegetarisch", "Vegan"],
"vegan": ["Vegan"]
}
WEEKDAYS = {
"montag": 1,
"dienstag": 2,
"mittwoch": 3,
"donnerstag": 4,
"freitag": 5,
"samstag": 6,
"sonntag": 7
}
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"]
diet = [""]
auto_next_day = True
today = datetime.datetime.now().date()
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:
date_offset = (6 - today.weekday() + WEEKDAYS[arg])
today += datetime.timedelta(days=date_offset)
auto_next_day = False
elif arg in DIETS:
diet = DIETS[arg]
else:
update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.")
return
if auto_next_day and datetime.datetime.now().time() > datetime.time(hour=16):
today += datetime.timedelta(days=1)
if today.weekday() == 6:
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)
if not today_data:
message = today.strftime("Kein Speiseplan für den %d.%m.%Y vorhanden")
else:
message = "Das Essen für %s in der %s \n\n" % (today_data["date"], MENSA_NAME[which])
for cat in today_data['categories']:
label = cat['name']
meals = cat['meals']
if label not in filter_categories and (
any(filtered in label for filtered in diet) or
[item['name'].replace('\xad', '') for item in meals if
any(filtered in item['name'].replace('\xad', '') for filtered in diet)]): # TODO: simplify
meal_line = "*%s*\n" % label
for meal in 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 data in complete_data['days']:
if day.isoformat() == data['iso-date']:
return data