From 45e177125cd7a10d65deedc2f4c6f8dcd670dbf4 Mon Sep 17 00:00:00 2001 From: mia Date: Sun, 7 Jun 2026 22:14:24 +0200 Subject: [PATCH] Fixed station monitor to be compatible with the backend. i tired, i eeps. --- station_monitor.py | 50 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/station_monitor.py b/station_monitor.py index 63d57b2..9707ef9 100644 --- a/station_monitor.py +++ b/station_monitor.py @@ -15,7 +15,6 @@ from prompt_toolkit.layout.containers import Window, VSplit, HSplit from prompt_toolkit.layout.controls import BufferControl from prompt_toolkit.key_binding import KeyBindings import threading -import time def run_station_monitor(hafas: backend.HafasClient | None = None): @@ -69,37 +68,38 @@ def run_station_monitor(hafas: backend.HafasClient | None = None): def handle_enter(event): global app_state - user_input = userinputBuffer.text.strip() + user_input = userinputBuffer.text.strip() + + if not user_input: + app_state = "MONITOR" + return - if user_input: app_state = "RESULTS" results = hafas.getStationNames(user_input) - + if not results: arrivalBuffer.text = f"Keine Stationen gefunden für: {user_input}" - departureBuffer.text= "" - userinputBuffer.text="" - app_state = "MONITOR" - - else: - station_name = results[0][1] - station_id = results[0][0] - - arrivals = hafas.getArrDep(station_id, arrdep="ARR", count=3) - arrivalBuffer.text = f"Ankünfte für {station_name}:\n" - for arrival in arrivals: - arrivalBuffer.insert_text(f"\n {arrival}") - - departures = hafas.getArrDep(station_id, arrdep="DEP", count=3) - departureBuffer.text = f"Abfahrten für {station_name}:\n" - for departure in departures: - departureBuffer.insert_text(f"\n {departure}") - - + departureBuffer.text = "" userinputBuffer.text = "" + app_state = "MONITOR" + return - else: - app_state = "MONITOR" + station_name = results[0][0] + station_id = results[0][1] + + arrivals = hafas.getArrDep(station_id, arrdep="ARR", count=5) + arrivalBuffer.text = ( + f"Ankünfte für {station_name}:\n" + + "\n".join(f" {arrival["departure_time"]} {arrival["line"]} --> {arrival["name"]}" for arrival in arrivals) + ) + + departures = hafas.getArrDep(station_id, arrdep="DEP", count=5) + departureBuffer.text = ( + f"Abfahrten für {station_name}:\n" + + "\n".join(f" {departure["departure_time"]} {departure["line"]} --> {departure["name"]}" for departure in departures) + ) + + userinputBuffer.text = "" @keyB.add("c-q")