From a05e208348607f5d3b91301a51cf9766d6cc6136 Mon Sep 17 00:00:00 2001 From: Filip Znachor Date: Mon, 12 Dec 2022 14:54:23 +0100 Subject: [PATCH] Added stops endpoint & updated app --- server/api.py | 29 +++++++++++++++----------- server/static/index.html | 44 +++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/server/api.py b/server/api.py index 1d35cae..5fe70e0 100644 --- a/server/api.py +++ b/server/api.py @@ -16,21 +16,26 @@ class Server(ServerAdapter): def stop(self): self.server.shutdown() -@route('/departures/') -def index(stop_id: int): - return {'departures': Departure.get(stop_id)} - -@get("/") -def static(): - return static_file("index.html", root="static") - -@error(404) -def error404(err): - return '' - class API: def __init__(self, main): + + @route('/departures/') + def departures(stop_id: int): + return {'departures': Departure.get(stop_id)} + + @route('/stops') + def stop(): + return {'stops': main.config["stops"]} + + @get("/") + def static(): + return static_file("index.html", root="static") + + @error(404) + def error404(err): + return '' + self.server = Server(host=main.config["http"]["host"], port=main.config["http"]["port"]) self.thread = threading.Thread(target=self.start) self.thread.start() diff --git a/server/static/index.html b/server/static/index.html index 15927ee..8f30e29 100644 --- a/server/static/index.html +++ b/server/static/index.html @@ -37,8 +37,8 @@