summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-06-26 22:22:47 +0200
committerDaniel Friesel <derf@finalrewind.org>2021-06-26 22:22:47 +0200
commit2cad8ef881b66b822769a15968f952bb2419f188 (patch)
treee2b3278293ebdd061f551d14ce7de00ce1f0c562 /bin
parentd21d35ef767007257e80a795a41b6f4cc8a9fcbc (diff)
add train station looukp by name
Diffstat (limited to 'bin')
-rwxr-xr-xbin/nvm18
1 files changed, 16 insertions, 2 deletions
diff --git a/bin/nvm b/bin/nvm
index 2603679..53cfb74 100755
--- a/bin/nvm
+++ b/bin/nvm
@@ -108,8 +108,7 @@ async def show_departure_board(request):
async with session.get(
f"{db_rest_api}/stops/{eva}/departures?results=60&duration=120&stopovers=true"
) as response:
- departures = await response.text()
- departures = json.loads(departures)
+ departures = await response.json()
if type(departures) is dict and departures.get("error", False):
return web.HTTPNotFound(body=json.dumps(departures), headers=headers)
@@ -127,6 +126,20 @@ async def show_departure_board(request):
)
+async def redirect_to_departure_board(request):
+ stop_name = request.query["name"]
+ async with aiohttp.ClientSession() as session:
+ async with session.get(
+ f"{db_rest_api}/locations?query={stop_name}&poi=false&addresses=false"
+ ) as response:
+ stops = await response.json()
+ stops_page = env.get_template("stops.html")
+ return web.Response(
+ body=stops_page.render(title="Noot", stops=stops),
+ headers=headers,
+ )
+
+
async def show_landing_page(request):
landing_page = env.get_template("landing_page.html")
return web.Response(
@@ -161,5 +174,6 @@ if __name__ == "__main__":
app.router.add_get(args.prefix, show_landing_page)
app.router.add_get(f"{args.prefix}board/{{eva}}", show_departure_board)
app.router.add_post(f"{args.prefix}geolocation", ajax_geolocation)
+ app.router.add_get(f"{args.prefix}find/stop", redirect_to_departure_board)
app.router.add_static(f"{args.prefix}static", "static")
web.run_app(app, host="localhost", port=args.port)