Browse Source

fixed filtering by diet

master
Angerstoner 6 years ago
parent
commit
0c8b0c15eb
  1. 27
      mensa.py
  2. 14
      schneiderbot.py

27
mensa.py

@ -5,9 +5,8 @@ import requests
DISABLED_GROUPS = [-1001301570558] DISABLED_GROUPS = [-1001301570558]
DIETS = { DIETS = {
"veggy": "fleischlos",
"fleisch": "mit Fleisch",
"fisch": "mit Fisch/Meeresfrüchten"
"veggy": ["Vegetarisch", "Vegan"],
"vegan": ["Vegan"]
} }
WEEKDAYS = { WEEKDAYS = {
@ -74,6 +73,7 @@ def mensa(bot, update, args):
return return
which = "zentral" which = "zentral"
filter_categories = MODES["light"] filter_categories = MODES["light"]
diet = [""]
auto_next_day = True auto_next_day = True
today = datetime.datetime.now().date() today = datetime.datetime.now().date()
@ -87,8 +87,8 @@ def mensa(bot, update, args):
date_offset = (6 - today.weekday() + WEEKDAYS[arg]) date_offset = (6 - today.weekday() + WEEKDAYS[arg])
today += datetime.timedelta(days=date_offset) today += datetime.timedelta(days=date_offset)
auto_next_day = False auto_next_day = False
# elif arg in DIETS:
# diet = DIETS[arg]
elif arg in DIETS:
diet = DIETS[arg]
else: else:
update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.") update.message.reply_text("Falscher Aufruf! RTFM und versuchs nochmal.")
return return
@ -111,9 +111,14 @@ def mensa(bot, update, args):
else: else:
message = "Das Essen für %s in der %s \n\n" % (today_data["date"], MENSA_NAME[which]) message = "Das Essen für %s in der %s \n\n" % (today_data["date"], MENSA_NAME[which])
for cat in today_data['categories']: for cat in today_data['categories']:
if cat['name'] not in filter_categories:
meal_line = "*%s*\n" % cat['name']
for meal in cat['meals']:
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" meal_line += meal['name'].strip() + "\n"
message += meal_line + '\n' message += meal_line + '\n'
@ -121,6 +126,6 @@ def mensa(bot, update, args):
def get_data_for_day(day, complete_data): def get_data_for_day(day, complete_data):
for date in complete_data['days']:
if day.isoformat() == date['iso-date']:
return date
for data in complete_data['days']:
if day.isoformat() == data['iso-date']:
return data

14
schneiderbot.py

@ -1,15 +1,17 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from telegram import ParseMode
from db import Db
from mensa import mensa
from coding_love import send_coding_love_gif
import logging import logging
import random import random
import requests
import pydog import pydog
import requests
from telegram import ParseMode
from telegram.ext import Updater, CommandHandler
from coding_love import send_coding_love_gif
from db import Db
from mensa import mensa
# Enable logging # Enable logging

Loading…
Cancel
Save