Skip to content

Commit

Permalink
feat: Add Mensa at Bildungscampus Heilbronn (#221)
Browse files Browse the repository at this point in the history
* feat: Add Mensa at Bildungscampus Heilbronn

* Remove poetry.lock
  • Loading branch information
PermissionError authored Oct 25, 2023
1 parent 2563190 commit 43aee84
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand All @@ -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).
Expand Down
7 changes: 7 additions & 0 deletions src/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
41 changes: 41 additions & 0 deletions src/menu_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

0 comments on commit 43aee84

Please sign in to comment.