Skip to content

Commit

Permalink
Add aliases for allergens
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Jan 27, 2024
1 parent 82a73dc commit 9b0e65e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion server/scraper/resto/allergens.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
"asc"
]

# Meals in the menu can have other names than here in the allergens.
# This maps allergen names to menu names, so we can include both.
ALIASES = {
"tortelloni in pittige tomatensaus": ["tortolloni in pittige tomatensaus"],
"penne prima vera": ["penne primavera"]
}


def get_section_indeces(raw_parts: list[Tag]) -> list[int]:
return [idx for idx, val in enumerate(raw_parts) if val.name == "h2"]
Expand Down Expand Up @@ -51,7 +58,18 @@ def parse_section_item(section_item: str) -> Union[dict[str, list[str]], None]:

# Exclude last item, it is not an allergen but a diet name
# eg. 'Vegetarian' or 'Vegan'
return {item_name.lower(): sorted({x for x in item_allergens if x not in SKIPPED_ELEMENTS})}
items = {item_name.lower(): sorted({x for x in item_allergens if x not in SKIPPED_ELEMENTS})}

# Add aliases if possible.
for original, copies in ALIASES.items():
try:
allergens = items[original]
for copy in copies:
if copy not in items:
items[copy] = allergens
except KeyError:
pass
return items


def make_sections(
Expand Down

0 comments on commit 9b0e65e

Please sign in to comment.