2022-04-23 10:15:17 +02:00
|
|
|
parser_list = {}
|
|
|
|
|
|
|
|
|
2023-02-04 18:17:34 +01:00
|
|
|
class Canteen:
|
|
|
|
canteen_id: str
|
|
|
|
suffix: str
|
|
|
|
name: str
|
|
|
|
street: str
|
|
|
|
city: str
|
|
|
|
|
|
|
|
def __init__(self, canteen_id, suffix, name, street, city):
|
|
|
|
self.canteen_id = canteen_id
|
|
|
|
self.suffix = suffix
|
|
|
|
self.name = name
|
|
|
|
self.street = street
|
|
|
|
self.city = city
|
|
|
|
|
|
|
|
def address(self):
|
|
|
|
return f'{self.street}, {self.city}'
|
|
|
|
|
|
|
|
|
2022-04-23 10:15:17 +02:00
|
|
|
class Parser:
|
2023-02-04 18:17:34 +01:00
|
|
|
canteens: dict[str, Canteen] = {}
|
2022-04-23 10:15:17 +02:00
|
|
|
|
2023-02-04 18:29:55 +01:00
|
|
|
def __init__(self, name, meal_data_handler, base_url: str):
|
2022-04-23 10:15:17 +02:00
|
|
|
self.name = name
|
2023-02-04 18:29:55 +01:00
|
|
|
self.meal_data_handler = meal_data_handler
|
|
|
|
self.base_url = base_url
|
2022-04-23 10:15:17 +02:00
|
|
|
parser_list[name] = self
|
|
|
|
|
2023-02-04 18:17:34 +01:00
|
|
|
def define(self, canteen: Canteen):
|
|
|
|
self.canteens[canteen.canteen_id] = canteen
|
|
|
|
|
2023-02-04 18:29:55 +01:00
|
|
|
def get_meal_data(self, canteen: str):
|
|
|
|
return self.meal_data_handler(self.base_url + self.canteens[canteen].suffix)
|
2022-04-23 10:15:17 +02:00
|
|
|
|
2023-02-04 18:17:34 +01:00
|
|
|
def get_canteen_index(self, prefix: str):
|
|
|
|
index: dict[str, str] = {}
|
|
|
|
canteen: Canteen
|
|
|
|
for canteen in self.canteens.values():
|
|
|
|
index[canteen.canteen_id] = f'{prefix}/{canteen.canteen_id}.xml'
|
|
|
|
return index
|
2022-04-23 10:15:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_parser(parser_name: str) -> Parser:
|
|
|
|
return parser_list[parser_name]
|