2023-02-04 18:17:34 +01:00
|
|
|
import os
|
|
|
|
|
2022-04-23 10:15:17 +02:00
|
|
|
from flask import Flask, abort
|
|
|
|
|
|
|
|
import parsers
|
|
|
|
import utils
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
parsers.define_parsers()
|
|
|
|
|
2023-02-04 19:20:01 +01:00
|
|
|
VIRTUAL_HOST = os.getenv('VIRTUAL_HOST')
|
|
|
|
|
2022-04-23 10:15:17 +02:00
|
|
|
|
2023-02-04 18:17:34 +01:00
|
|
|
@app.route('/mensa/<parser_name>.json')
|
|
|
|
def index(parser_name):
|
2022-04-23 10:15:17 +02:00
|
|
|
try:
|
2023-02-04 20:34:59 +01:00
|
|
|
return utils.get_parser(parser_name).get_canteen_index(f'http://{VIRTUAL_HOST}/mensa/{parser_name}/meta')
|
2023-02-04 19:20:01 +01:00
|
|
|
except KeyError:
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
|
2023-02-04 20:34:59 +01:00
|
|
|
@app.route('/mensa/<parser_name>/meta/<canteen_name>.xml')
|
2023-02-04 19:20:01 +01:00
|
|
|
def meta(parser_name, canteen_name):
|
|
|
|
try:
|
|
|
|
return utils.get_parser(parser_name).get_meta_data(canteen_name, f'http://{VIRTUAL_HOST}/mensa/{parser_name}/feed')
|
2022-04-23 10:15:17 +02:00
|
|
|
except KeyError:
|
|
|
|
abort(404)
|
|
|
|
|
2023-02-04 18:17:34 +01:00
|
|
|
|
2023-02-04 20:34:59 +01:00
|
|
|
@app.route('/mensa/<parser_name>/feed/<canteen_name>.xml')
|
2023-02-04 18:17:34 +01:00
|
|
|
def mensa(parser_name, canteen_name):
|
|
|
|
try:
|
2023-02-04 18:29:55 +01:00
|
|
|
return utils.get_parser(parser_name).get_meal_data(canteen_name)
|
2023-02-04 18:17:34 +01:00
|
|
|
except KeyError:
|
|
|
|
abort(404)
|