From 2cad8ef881b66b822769a15968f952bb2419f188 Mon Sep 17 00:00:00 2001
From: Daniel Friesel
Date: Sat, 26 Jun 2021 22:22:47 +0200
Subject: add train station looukp by name
---
bin/nvm | 18 ++++++++++++++++--
templates/landing_page.html | 4 ++--
templates/stops.html | 30 ++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 4 deletions(-)
create mode 100644 templates/stops.html
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)
diff --git a/templates/landing_page.html b/templates/landing_page.html
index a059b55..f487616 100644
--- a/templates/landing_page.html
+++ b/templates/landing_page.html
@@ -23,13 +23,13 @@
-
+
+
+
diff --git a/templates/stops.html b/templates/stops.html
new file mode 100644
index 0000000..4f31c0a
--- /dev/null
+++ b/templates/stops.html
@@ -0,0 +1,30 @@
+
+
+