summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-07-12 19:32:52 +0200
committerDaniel Friesel <derf@finalrewind.org>2021-07-12 19:32:52 +0200
commit640df543aad9267c3a15922ab7fb6e4ae14a25ce (patch)
treede9c067e27781230296b835c80d52ce9a121ac15
parent12ea2edf8e9afa531e4ac799085d02a635c4dfcb (diff)
show stop directly if searched name is an exact match
-rwxr-xr-xbin/nvm21
1 files changed, 15 insertions, 6 deletions
diff --git a/bin/nvm b/bin/nvm
index 610fe3d..fcca040 100755
--- a/bin/nvm
+++ b/bin/nvm
@@ -250,11 +250,13 @@ class Line:
return self.name
-async def show_departure_board(request):
- try:
- eva = int(request.match_info.get("eva"))
- except ValueError:
- return web.HTTPBadRequest(text="EVA must be a number at the moment")
+async def show_departure_board(request, eva=None):
+
+ if eva is None:
+ try:
+ eva = int(request.match_info.get("eva"))
+ except ValueError:
+ return web.HTTPBadRequest(text="EVA must be a number at the moment")
request_url = (
f"{db_rest_api}/stops/{eva}/departures?results=60&duration=120&stopovers=true"
@@ -314,6 +316,11 @@ async def redirect_to_departure_board(request):
async with aiohttp.ClientSession() as session:
async with session.get(request_url) as response:
stops = await response.json()
+
+ for stop in stops:
+ if stop_name.lower() == stop["name"].lower():
+ return await show_departure_board(request, stop["id"])
+
stops_page = env.get_template("stops.html")
return web.Response(
body=stops_page.render(title=f"Suche nach „{stop_name}“", stops=stops),
@@ -333,7 +340,9 @@ async def ajax_geolocation(request):
request_data = await request.json()
lat = request_data["lat"]
lon = request_data["lon"]
- request_url = f"{db_rest_api}/stops/nearby?latitude={lat}&longitude={lon}&results=10"
+ request_url = (
+ f"{db_rest_api}/stops/nearby?latitude={lat}&longitude={lon}&results=10"
+ )
logging.debug(f"Requesting stops near {lat}/{lon} from {request_url}")
async with aiohttp.ClientSession() as session:
async with session.get(request_url) as response: