diff --git a/RMV_Digital_Board_light.py b/RMV_Digital_Board_light.py index 0918bd7..f675db6 100644 --- a/RMV_Digital_Board_light.py +++ b/RMV_Digital_Board_light.py @@ -39,6 +39,7 @@ import argparse import requests import time import json +import re from datetime import datetime from rich.console import Console, Group from rich.table import Table @@ -124,6 +125,15 @@ def fetch_departures(start_id, max_journeys=12): departures = data["Departure"] if isinstance(data["Departure"], list) else [data["Departure"]] return departures +def _parse_mins(cell) -> int: + """Wandelt '15 Min', '0 Min' oder 'Jetzt' in eine Zahl um (für Sortierung).""" + if isinstance(cell, int): + return cell + s = str(cell).strip().lower() + if s == "jetzt": + return 0 + m = re.search(r"-?\d+", s) + return int(m.group()) if m else 999 # Unbekanntes/fehlendes ans Ende def build_table_data(departures): """Erzeugt Datenlisten für West- und Ost-Richtung.""" @@ -183,6 +193,10 @@ def run_terminal_mode(): departures = fetch_departures(START_ID) now, west, east = build_table_data(departures) + # KORREKTE NUMERISCHE SORTIERUNG + west.sort(key=lambda row: _parse_mins(row[2])) + east.sort(key=lambda row: _parse_mins(row[2])) + table_west = Table(title=f"← Richtung Frankfurt (Westen) – {now}") table_west.add_column("Linie", justify="center", style="cyan", no_wrap=True) table_west.add_column("Ziel", justify="left", style="magenta") @@ -262,9 +276,9 @@ class RMVApp(App): departures = fetch_departures(self.current_id) _, west, east = build_table_data(departures) - # Sortieren nach Minutenwert, wie im Lightmodus - west.sort(key=lambda row: int(row[2]) if row[2].isdigit() else 999) - east.sort(key=lambda row: int(row[2]) if row[2].isdigit() else 999) + # KORREKTE NUMERISCHE SORTIERUNG + west.sort(key=lambda row: _parse_mins(row[2])) + east.sort(key=lambda row: _parse_mins(row[2])) self.update_table(self.table_west, west) self.update_table(self.table_east, east)