diff --git a/backend.py b/backend.py index 03bc604..6ace7d0 100644 --- a/backend.py +++ b/backend.py @@ -9,6 +9,7 @@ The application will provide routing information and station departures/arrivals import requests import json +import re from datetime import datetime from prompt_toolkit import Application from prompt_toolkit.completion import WordCompleter @@ -75,20 +76,13 @@ class HafasClient: # - Departure/arrival time: departure["stbStop"]["dTimeS"] or ["aTimeS"] departures.append({ "name": departure.get("dirTxt"), - "line": ( - product.get("nameS") - or product.get("number") - or product.get("name") - or product.get("prodCtx", {}).get("line") - or product.get("prodCtx", {}).get("name") - or product.get("prodCtx", {}).get("nameS") - ), + "line": re.search(r'#ZB#([^#]+)', departure.get("jid")).group(1).strip(), "departure_time": self._format_time(stop.get(time_key)), "departure_time_raw": stop.get(time_key), "departure_time_real": self._format_time(stop.get(time_key_real)), "departure_time_real_raw": stop.get(time_key_real), "jid": departure.get("jid"), - "raw": departure, + # "raw": departure, }) return departures @@ -114,13 +108,19 @@ class HafasClient: trip = self.getTrip(departures[0]["jid"]) __import__('pprint').pprint(trip) - def moniterTest(self): + def monitorTest(self): stationInput = input("Enter Station Name: ") station = self.getStationNames(stationInput) print(station) # departures = self.getArrDep(station[0][1], arrdep="DEP", count=1) - departures = self.arrDepRequest(station[0][1], arrdep="DEP", count=1) - print(departures) + print("\n)------------------\n") + departures = self.getArrDep(station[0][1], arrdep="DEP", count=2) + __import__('pprint').pprint(departures) + print("\n)------------------\n") + arrivals = self.getArrDep(station[0][1], arrdep="ARR", count=2) + __import__('pprint').pprint(arrivals) + #arrivalsRaw = self.arrDepRequest(station[0][1], arrdep="ARR", count=1) + #__import__('pprint').pprint(arrivalsRaw) # streq = self.stationRequest(station)["svcResL"][0]["res"]["match"]["locL"] @@ -140,4 +140,4 @@ class HafasClient: if __name__ == '__main__': client = HafasClient() # client.runTests() - client.moniterTest() + client.monitorTest() diff --git a/station_monitor.py b/station_monitor.py index 9707ef9..cf83336 100644 --- a/station_monitor.py +++ b/station_monitor.py @@ -90,13 +90,13 @@ def run_station_monitor(hafas: backend.HafasClient | None = None): 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) + + "\n".join(f" {arrival["departure_time_real"]} {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) + + "\n".join(f" {departure["departure_time_real"]} {departure["line"]} --> {departure["name"]}" for departure in departures) ) userinputBuffer.text = ""