From 43aee84ceeeedfb17f10128acd19cfdbb0c7379c Mon Sep 17 00:00:00 2001 From: Ray Ma <27805472+PermissionError@users.noreply.github.com> Date: Wed, 25 Oct 2023 17:25:52 +0200 Subject: [PATCH] feat: Add Mensa at Bildungscampus Heilbronn (#221) * feat: Add Mensa at Bildungscampus Heilbronn * Remove poetry.lock --- .gitignore | 1 + README.md | 3 ++- src/entities.py | 7 +++++++ src/main.py | 1 + src/menu_parser.py | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index da1cf741de..aec4b6d629 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ wheels/ *.egg-info/ .installed.cfg *.egg +poetry.lock # PyInstaller # Usually these files are written by a python script from a template diff --git a/README.md b/README.md index 2f1d297226..3b79437cf3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Simple static API for the canteens of the [Studierendenwerk München Oberbayern](http://www.studierendenwerk-muenchen-oberbayern.de) as well as some other canteens. By now, the following canteens are supported: | Name | API-key | Address | -| :----------------------------- | :----------------------------- |:----------------------------------------------------------------------------------------------------------------------------| +|:-------------------------------|:-------------------------------|:----------------------------------------------------------------------------------------------------------------------------| | Mensa Arcisstraße | mensa-arcisstr | [Arcisstraße 17, München](https://www.google.com/maps?q=Arcisstraße+17,+München) | | Mensa Garching | mensa-garching | [Boltzmannstraße 19, Garching](https://www.google.com/maps?q=Boltzmannstraße+19,+Garching) | | Mensa Leopoldstraße | mensa-leopoldstr | [Leopoldstraße 13a, München](https://www.google.com/maps?q=Leopoldstraße+13a,+München) | @@ -29,6 +29,7 @@ Simple static API for the canteens of the [Studierendenwerk München Oberbayern] | StuCafé Pasing | stucafe-pasing | [Am Stadtpark 20, München](https://www.google.com/maps?q=Am%20Stadtpark+20,+München) | | FMI Bistro Garching | fmi-bistro | [Boltzmannstraße 3, Garching](https://www.google.com/maps?q=Boltzmannstraße+3,+Garching) | | IPP Bistro Garching | ipp-bistro | [Boltzmannstraße 2, Garching](https://goo.gl/maps/vYdsQhgxFvH2) | +| Mensa Bildungscampus Heilbronn | mensa-bildungscampus-heilbronn | [Bildungscampus 8, Heilbronn](https://maps.app.goo.gl/Jq2p9fKkjTMPrvd39) | ## Label list - previously _ingredients_: See [here](https://tum-dev.github.io/eat-api/enums/labels.json). diff --git a/src/entities.py b/src/entities.py index 25637fd90e..8457093438 100644 --- a/src/entities.py +++ b/src/entities.py @@ -366,6 +366,13 @@ def __init__(self, long_name: str, location: Location, url_id: int, queue_status None, OpenHours(("07:30", "15:00"), ("07:30", "15:00"), ("07:30", "15:00"), ("07:30", "15:00"), ("07:30", "14:30")), ) + MENSA_BILDUNGSCAMPUS_HEILBRONN = ( + "Mensa Buildungscampus Heilbronn", + Location("Bildungscampus 8, 74076 Heilbronn", 49.14863559683538, 9.21598792582061), + None, + None, + OpenHours(("11:00", "14:30"), ("11:00", "14:30"), ("11:00", "14:30"), ("11:00", "14:30"), ("11:00", "14:30")), + ) @staticmethod def get_canteen_by_str(canteen_str: str) -> Canteen: diff --git a/src/main.py b/src/main.py index ae3216f224..37b78f3990 100644 --- a/src/main.py +++ b/src/main.py @@ -24,6 +24,7 @@ def get_menu_parsing_strategy(canteen: Canteen) -> Optional[menu_parser.MenuPars menu_parser.IPPBistroMenuParser, menu_parser.MedizinerMensaMenuParser, menu_parser.StraubingMensaMenuParser, + menu_parser.MensaBildungscampusHeilbronnParser, } # set parsing strategy based on canteen for parser in parsers: diff --git a/src/menu_parser.py b/src/menu_parser.py index bc2073a022..bd00615192 100644 --- a/src/menu_parser.py +++ b/src/menu_parser.py @@ -1125,3 +1125,44 @@ def _marks_to_labels(cls, marks: str) -> List[Label]: labels.extend(mark_to_label.get(mark, [])) return labels + + +class MensaBildungscampusHeilbronnParser(MenuParser): + base_url = "https://openmensa.org/api/v2/canteens/277" + canteens = {Canteen.MENSA_BILDUNGSCAMPUS_HEILBRONN} + + def parse(self, canteen: Canteen) -> Optional[Dict[datetime.date, Menu]]: + menus = {} + + def mutate(element): + return Dish( + element["name"], + Prices( + Price(0, element["prices"]["students"], "Portion"), + Price(0, element["prices"]["employees"], "Portion"), + Price(0, element["prices"]["others"], "Portion"), + ), + set(), + element["category"], + ) + + for date in self.__get_available_dates(): + dateobj: datetime.date = datetime.datetime.strptime(date, "%Y-%m-%d").date() + page_link: str = self.base_url + "/days/" + date + "/meals" + page: requests.Response = requests.get(page_link, timeout=10.0) + if page.ok: + dishes: List = list(map(mutate, page.json())) + menus[dateobj] = Menu(dateobj, dishes) + return menus + + def __get_available_dates(self): + days: List = requests.get(self.base_url + "/days", timeout=10.0).json() + + # Weed out the closed days + def predicate(element): + return not element["closed"] + + def mutate(element): + return element["date"] + + return list(map(mutate, filter(predicate, days)))