diff --git a/app.py b/app.py index 16cdae2..97c71d1 100644 --- a/app.py +++ b/app.py @@ -22,6 +22,6 @@ def index(parser_name): @app.route('/mensa//feed/') def mensa(parser_name, canteen_name): try: - return utils.get_parser(parser_name).parse(canteen_name) + return utils.get_parser(parser_name).get_meal_data(canteen_name) except KeyError: abort(404) diff --git a/parsers/tuebingen.py b/parsers/tuebingen.py index 734a518..52087c5 100644 --- a/parsers/tuebingen.py +++ b/parsers/tuebingen.py @@ -52,7 +52,7 @@ legend = { multiple_whitespaces_regex = re.compile('\\s{2,}') -def parse_url(url, today=False): +def get_meal_data(url, today=False): canteen = LazyBuilder() with urlopen(Request(url, None, {'User-Agent': 'Mozilla/5.0'})) as response: data = json.loads(response.read()) @@ -88,6 +88,7 @@ def define_parsers(): with open('parsers/tuebingen.json') as canteen_file: canteen_json = json.load(canteen_file) - parser = Parser(canteen_json['name'], handler=parse_url, shared_prefix=canteen_json['base_url']) + parser = Parser(canteen_json['name'], meal_data_handler=get_meal_data, + base_url=canteen_json['base_url']) for canteen in canteen_json['canteens']: parser.define(Canteen(canteen['id'], canteen['suffix'], canteen['name'], canteen['street'], canteen['city'])) diff --git a/utils.py b/utils.py index 2adb9b5..f34bca1 100644 --- a/utils.py +++ b/utils.py @@ -22,17 +22,17 @@ class Canteen: class Parser: canteens: dict[str, Canteen] = {} - def __init__(self, name, handler, shared_prefix: str): + def __init__(self, name, meal_data_handler, base_url: str): self.name = name - self.handler = handler - self.shared_prefix = shared_prefix + self.meal_data_handler = meal_data_handler + self.base_url = base_url parser_list[name] = self def define(self, canteen: Canteen): self.canteens[canteen.canteen_id] = canteen - def parse(self, canteen: str): - return self.handler(self.shared_prefix + self.canteens[canteen].suffix) + def get_meal_data(self, canteen: str): + return self.meal_data_handler(self.base_url + self.canteens[canteen].suffix) def get_canteen_index(self, prefix: str): index: dict[str, str] = {}