summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/nvm18
-rw-r--r--templates/landing_page.html4
-rw-r--r--templates/stops.html30
3 files changed, 48 insertions, 4 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)
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 @@
<div class="geolocation">
<button id="geolocationsearch">Haltestellen in der Umgebung suchen</button>
</div>
- <!--<form action="/to_board" method="POST">
+ <form action="/find/stop">
<input id="name" name="name" required type="text">
<label for="name">Manuelle Eingabe</label>
<button class="btn waves-effect waves-light btn-flat" type="submit" name="action" value="departures">
Suchen
</button>
- </form>-->
+ </form>
</div>
</div>
</body>
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 @@
+<!DOCTYPE html>
+<html lang="de">
+<head>
+ <title>{{ title }}</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <meta name="keywords" content="Abfahrtsmonitor, Bahnhofstafel, Abfahrten, Abfahrtstafel, Nahverkehr, Haltestellen">
+ <meta name="description" content="Inoffizieller Abfahrtsmonitor für Nahverkehr">
+ <meta name="theme-color" content="#00838f">
+ <link rel="icon" type="image/png" href="/static/icons/icon-16x16.png" sizes="16x16">
+ <link rel="icon" type="image/png" href="/static/icons/icon-32x32.png" sizes="32x32">
+ <link rel="icon" type="image/png" href="/static/icons/icon-96x96.png" sizes="96x96">
+ <link rel="apple-touch-icon" href="/static/icons/icon-120x120.png">
+ <link rel="apple-touch-icon" sizes="180x180" href="/static/icons/icon-180x180.png">
+ <link rel="apple-touch-icon" sizes="152x152" href="/static/icons/icon-152x152.png">
+ <link rel="apple-touch-icon" sizes="167x167" href="/static/icons/icon-167x167.png">
+ <link href="/static/v0/css/wip.css" id="theme" rel="stylesheet">
+</head>
+<body>
+<div class="container">
+ <div class="content">
+ <ul>
+ {% for stop in stops %}
+ <li><a href="/board/{{ stop['id'] }}">{{ stop['name'] }}</a></li>
+ {% endfor %}
+ </ul>
+ </div>
+</div>
+</body>
+</html>