Handle offers without a category

This commit is contained in:
f4lco
2021-01-27 20:54:48 +01:00
parent 4fad78261a
commit 9850231c4f
4 changed files with 2395 additions and 1 deletions
+8 -1
View File
@@ -42,13 +42,20 @@ def _prices(offer):
def _process_day(builder, day): def _process_day(builder, day):
for offer in _offers(day): for offer in _offers(day):
builder.addMeal(date=day['data'], builder.addMeal(date=day['data'],
category=offer['titel'], category=_category(offer),
name=offer['beschreibung'], name=offer['beschreibung'],
notes=_notes(offer), notes=_notes(offer),
prices=_prices(offer), prices=_prices(offer),
roles=None) roles=None)
def _category(offer):
# 'Angebot' is just a placeholder. We cannot tell if 'Angebot' or 'Info' is
# more appropriate because offers lacking the 'titel' attribute are real
# meals or informational texts.
return offer['titel'] or 'Angebot'
def _offers(day): def _offers(day):
offers = day['angebote'] offers = day['angebote']
if isinstance(offers, list): if isinstance(offers, list):
+133
View File
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<openmensa version="2.1" xmlns="http://openmensa.org/open-mensa-v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://openmensa.org/open-mensa-v2 http://openmensa.org/open-mensa-v2.xsd">
<canteen>
<day date="2021-01-27">
<category name="Angebot 3">
<meal>
<name>a</name>
<price role="employee">4.50</price>
<price role="other">4.50</price>
<price role="student">2.60</price>
</meal>
<meal>
<name>Fangfrisches Lachsfilet auf Blattspinat, dazu Grillkartoffeln</name>
<note>Fisch</note>
<price role="employee">4.50</price>
<price role="other">4.50</price>
<price role="student">2.60</price>
</meal>
</category>
<category name="Angebot">
<meal>
<name>Linsensuppe mit Wiener Würstchen, dazu Brot</name>
<note>Rind</note>
<note>Schwein</note>
<price role="other">3.10</price>
<price role="student">1.60</price>
</meal>
</category>
<category name="Angebot 1">
<meal>
<name>Vegane Frühlingsrolle mit Kokos- Currysauce, dazu Wokgemüse und Langkornreis</name>
<note>Knoblauch</note>
<note>Vegan</note>
<price role="other">4.50</price>
<price role="student">2.60</price>
</meal>
</category>
<category name="Info">
<meal>
<name>Die Mensen Am Neuen Palais und Golm bleiben geöffnet.
Sie können Ihr Mittagessen vor Ort verzehren oder to go mitnehmen.
Der Foodhopper in der Kaiser-Friedrich-Straße bietet ausschließlich Mittagessen to go an.</name>
<price role="employee">3.90</price>
<price role="other">0.00</price>
<price role="student">0.00</price>
</meal>
</category>
</day>
<day date="2021-01-28">
<category name="Angebot 3">
<meal>
<name>Veganes Sojasteak mit geschmorten Zwiebeln, dazu Bratkartoffeln und Salat</name>
<note>Vegan</note>
<price role="employee">4.50</price>
<price role="other">4.50</price>
<price role="student">2.60</price>
</meal>
<meal>
<name>Schweinenackensteak mit geschmorten Zwiebeln, dazu Bratkartoffeln und Salat</name>
<note>Schwein</note>
<price role="employee">4.50</price>
<price role="other">4.50</price>
<price role="student">2.60</price>
</meal>
</category>
<category name="Angebot 1">
<meal>
<name>Nudeln mit Bolognesesauce</name>
<note>Knoblauch</note>
<note>Rind</note>
<price role="other">3.10</price>
<price role="student">1.60</price>
</meal>
</category>
<category name="Info">
<meal>
<name>Die Mensen Am Neuen Palais und Golm bleiben geöffnet.
Sie können Ihr Mittagessen vor Ort verzehren oder to go mitnehmen.
Der Foodhopper in der Kaiser-Friedrich-Straße bietet ausschließlich Mittagessen to go an.</name>
<price role="employee">3.90</price>
<price role="other">0.00</price>
<price role="student">0.00</price>
</meal>
</category>
</day>
<day date="2021-01-29">
<category name="Angebot">
<meal>
<name>Die Mensen Am Neuen Palais und Golm bleiben geöffnet.
Sie können Ihr Mittagessen vor Ort verzehren oder to go mitnehmen.
Der Foodhopper in der Kaiser-Friedrich-Straße bietet ausschließlich Mittagessen to go an.</name>
<price role="employee">3.90</price>
<price role="other">3.90</price>
<price role="student">2.10</price>
</meal>
<meal>
<name>Hefeklöße mit heißen Früchten</name>
<note>Vegetarisch</note>
</meal>
<meal>
<name>Germknödel mit Vanillesauce</name>
<note>Alkohol</note>
<note>Vegetarisch</note>
</meal>
</category>
<category name="Angebot 3">
<meal>
<name>Vegane Gemüsefrikdelle mit Ajvar-Dip, dazu Bulgur und Salat</name>
<note>Vegan</note>
<price role="employee">4.50</price>
<price role="other">4.50</price>
<price role="student">2.60</price>
</meal>
</category>
<category name="Angebot 1">
<meal>
<name>Currywurst mit hausgemachter Sauce, dazu Pommes frites und Salat</name>
<note>Schwein</note>
</meal>
</category>
</day>
<day date="2021-02-01">
<category name="Info">
<meal>
<name>Liebe Gäste! Den Speiseplan der laufenden Woche finden Sie immer montags hier .</name>
<price role="employee">3.10</price>
<price role="other">3.10</price>
<price role="student">1.60</price>
</meal>
</category>
</day>
</canteen>
</openmensa>
File diff suppressed because it is too large Load Diff
+10
View File
@@ -62,3 +62,13 @@ def test_offers_dictionary():
expected = _read_feed('offers-dict-output.xml') expected = _read_feed('offers-dict-output.xml')
assert expected == actual assert expected == actual
def test_missing_category():
menu = _read_menu('missing-category.json')
actual = feed.render_menu(menu)
expected = _read_feed('missing-category-output.xml')
assert expected == actual