Rename variables for better clarity and consistency
This commit is contained in:
parent
64e52acbdb
commit
d60ce9d0bc
3 changed files with 9 additions and 8 deletions
2
app.py
2
app.py
|
@ -22,6 +22,6 @@ def index(parser_name):
|
|||
@app.route('/mensa/<parser_name>/feed/<canteen_name>')
|
||||
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)
|
||||
|
|
|
@ -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']))
|
||||
|
|
10
utils.py
10
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] = {}
|
||||
|
|
Loading…
Reference in a new issue