summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-03-28 21:28:09 +0200
committerDaniel Friesel <derf@finalrewind.org>2021-03-28 21:28:09 +0200
commita7021a0d80743f3c7221c7fa07912d3ee12be99c (patch)
tree7194e28732ff19ea08f691267e1754d13188fb8e
parent67dc1dfb6f2dead0e14e671e407859e21b1f02b9 (diff)
adjust lookup-server for dbf
-rwxr-xr-xbin/lookup-server22
1 files changed, 16 insertions, 6 deletions
diff --git a/bin/lookup-server b/bin/lookup-server
index 615f363..8d26dbe 100755
--- a/bin/lookup-server
+++ b/bin/lookup-server
@@ -104,15 +104,25 @@ def calculate_distance(train, latlon):
def format_train(train):
+ train_type, line_no = train["line"]["name"].split()
+ train_no = train["line"]["fahrtNr"]
return {
- "line": train["line"]["name"],
- "no": train["line"]["fahrtNr"],
+ "line": f"{train_type} {line_no}",
+ "train": f"{train_type} {train_no}",
"tripId": train["tripId"],
"location": train["coarse_location"],
- "distance": train["distance"],
+ "distance": round(train["distance"], 1),
"stops": [
- (train["evas"][0], train["stop_names"][0], train["times"][0].isoformat()),
- (train["evas"][1], train["stop_names"][1], train["times"][1].isoformat()),
+ (
+ train["evas"][0],
+ train["stop_names"][0],
+ train["times"][0].strftime("%H:%M"),
+ ),
+ (
+ train["evas"][1],
+ train["stop_names"][1],
+ train["times"][1].strftime("%H:%M"),
+ ),
],
}
@@ -185,7 +195,7 @@ async def handle_search(request):
calculate_distance(train, (lat, lon))
trains = sorted(trains, key=lambda train: train["distance"])
- trains = list(map(format_train, trains))
+ trains = list(map(format_train, trains[:10]))
response = {"evas": list(evas), "trains": trains}