diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-03-28 21:28:09 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-03-28 21:28:09 +0200 |
commit | a7021a0d80743f3c7221c7fa07912d3ee12be99c (patch) | |
tree | 7194e28732ff19ea08f691267e1754d13188fb8e | |
parent | 67dc1dfb6f2dead0e14e671e407859e21b1f02b9 (diff) |
adjust lookup-server for dbf
-rwxr-xr-x | bin/lookup-server | 22 |
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} |