Skip to content
This repository has been archived by the owner on Nov 20, 2022. It is now read-only.

Commit

Permalink
Add Aktionsgericht to FMI Mensa (#22)
Browse files Browse the repository at this point in the history
* Add Aktionsgericht to FMI Mensa

* Fallback to three dishes in case there is no aktionsgericht

* Make tests work

* Use filter instead of a list comp
  • Loading branch information
kordianbruck authored and srehwald committed Feb 27, 2018
1 parent 0abd45d commit ff50794
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
24 changes: 21 additions & 3 deletions src/menu_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ def get_menus(self, text, year, week_number):
lines_weekdays["thu"] += " " + line[pos_thu:pos_fri].replace("\n", " ").replace("Donnerstag", "")
lines_weekdays["fri"] += " " + line[pos_fri:].replace("\n", " ").replace("Freitag", "")

# Add the aktionsgericht
line_aktion = [s for s in lines if "Aktion" in s]
num_dishes = 3
if len(line_aktion) == 1:
line_aktion_pos = lines.index(line_aktion[0]) - 2
aktionsgericht = ' '.join(lines[line_aktion_pos:line_aktion_pos + 3])
aktionsgericht = aktionsgericht \
.replace("Montag – Freitag", "") \
.replace("Tagessuppe täglich wechselndes Angebot", "") \
.replace("ab € 1,00", "") \
.replace("Aktion", "")
num_dishes += aktionsgericht.count('€')
for key in lines_weekdays:
lines_weekdays[key] = aktionsgericht + ", " + lines_weekdays[key]

# Process menus for each day
for key in lines_weekdays:
# stop parsing day when bistro is closed at that day
if "geschlossen" in lines_weekdays[key].lower():
Expand All @@ -241,9 +257,11 @@ def get_menus(self, text, year, week_number):
# convert prices to float
prices = [float(price.replace("€", "").replace(",", ".").strip()) for price in prices]
# remove price and commas from dish names
dish_names = [re.sub(self.price_regex, "", dish).replace("," ,"").strip() for dish in dish_names]
# create list of Dish objects; only take first 3 as the following dishes are corrupt and not necessary
dishes = [Dish(dish_name, price) for (dish_name, price) in list(zip(dish_names, prices))][:3]
dish_names = [re.sub(self.price_regex, "", dish).replace(",", "").strip() for dish in dish_names]
# create list of Dish objects; only take first 3/4 as the following dishes are corrupt and not necessary
dishes = [Dish(dish_name, price) for (dish_name, price) in list(zip(dish_names, prices))][:num_dishes]
# filter empty dishes
dishes = list(filter(lambda x: x.name != "", dishes))
# get date from year, week number and current weekday
# https://stackoverflow.com/questions/17087314/get-date-from-week-number
date_str = "%d-W%d-%d" % (year, week_number, self.weekday_positions[key])
Expand Down
19 changes: 11 additions & 8 deletions src/test/test_menu_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class FMIBistroParserTest(unittest.TestCase):
date_mon1 = date(2017, 10, 30)
date_thu1 = date(2017, 11, 2)
date_fri1 = date(2017, 11, 3)

dish_aktion1 = Dish("Tellerfleisch mit Bouillonkartoffeln und Sahnemeerrettich Kaiserschmarrn mit Zwetschenröster", 3.0)
dish1_mon1 = Dish("Kurkumareis mit Asia Wokgemüse", 3.6)
dish2_mon1 = Dish("Kartoffel „Cordon Bleu“ mit Frischkäse gefüllt dazu Blattsalate", 4.3)
dish3_mon1 = Dish("Putenschnitzel natur mit Paprikarahmsoße dazu Ebly Gemüseweizen", 5.3)
Expand All @@ -161,15 +163,16 @@ class FMIBistroParserTest(unittest.TestCase):
dish1_fri1 = Dish("Antipasti Rosmarinkartoffeln", 3.6)
dish2_fri1 = Dish("Schlemmerfilet auf Antipasti Rosmarinkartoffeln", 4.5)
dish3_fri1 = Dish("Kaiserschmarrn mit Zwetschenröster", 3)
menu_mon1 = Menu(date_mon1, [dish1_mon1, dish2_mon1, dish3_mon1])
menu_thu1 = Menu(date_thu1, [dish1_thu1, dish2_thu1, dish3_thu1])
menu_fri1 = Menu(date_fri1, [dish1_fri1, dish2_fri1, dish3_fri1])
menu_mon1 = Menu(date_mon1, [dish_aktion1, dish1_mon1, dish2_mon1, dish3_mon1])
menu_thu1 = Menu(date_thu1, [dish_aktion1, dish1_thu1, dish2_thu1, dish3_thu1])
menu_fri1 = Menu(date_fri1, [dish_aktion1, dish1_fri1, dish2_fri1, dish3_fri1])

date_mon2 = date(2017, 11, 6)
date_tue2 = date(2017, 11, 7)
date_wed2 = date(2017, 11, 8)
date_thu2 = date(2017, 11, 9)
date_fri2 = date(2017, 11, 10)
dish_aktion2 = Dish("Pochiertes Lachsfilet mit Dillsoße dazu Minze-Reis", 6.5)
dish1_mon2 = Dish("Dampfkartoffeln mit Zucchinigemüse", 3.6)
dish2_mon2 = Dish("Valess-Schnitzel mit Tomaten-Couscous", 4.3)
dish3_mon2 = Dish("Kasslerpfanne mit frischen Champignons und Spätzle", 4.9)
Expand All @@ -183,11 +186,11 @@ class FMIBistroParserTest(unittest.TestCase):
dish1_fri2 = Dish("Spiralnudeln mit Ratatouillegemüse", 3.6)
dish2_fri2 = Dish("Milchreis mit warmen Sauerkirschen", 3)
dish3_fri2 = Dish("Lasagne aus Seelachs und Blattspinat", 5.3)
menu_mon2 = Menu(date_mon2, [dish1_mon2, dish2_mon2, dish3_mon2])
menu_tue2 = Menu(date_tue2, [dish1_tue2, dish2_tue2])
menu_wed2 = Menu(date_wed2, [dish1_wed2, dish2_wed2])
menu_thu2 = Menu(date_thu2, [dish1_thu2, dish2_thu2, dish3_thu2])
menu_fri2 = Menu(date_fri2, [dish1_fri2, dish2_fri2, dish3_fri2])
menu_mon2 = Menu(date_mon2, [dish_aktion2, dish1_mon2, dish2_mon2, dish3_mon2])
menu_tue2 = Menu(date_tue2, [dish_aktion2, dish1_tue2, dish2_tue2])
menu_wed2 = Menu(date_wed2, [dish_aktion2, dish1_wed2, dish2_wed2])
menu_thu2 = Menu(date_thu2, [dish_aktion2, dish1_thu2, dish2_thu2, dish3_thu2])
menu_fri2 = Menu(date_fri2, [dish_aktion2, dish1_fri2, dish2_fri2, dish3_fri2])

def test_Should_Return_Menu(self):
menus_actual1 = self.bistro_parser.get_menus(self.test_menu1, self.year1, self.week_number1)
Expand Down

0 comments on commit ff50794

Please sign in to comment.