finally fixed line numbers, improved rendering of station monitor
This commit is contained in:
parent
45e177125c
commit
dfb2e2716d
2 changed files with 15 additions and 15 deletions
26
backend.py
26
backend.py
|
|
@ -9,6 +9,7 @@ The application will provide routing information and station departures/arrivals
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from prompt_toolkit import Application
|
from prompt_toolkit import Application
|
||||||
from prompt_toolkit.completion import WordCompleter
|
from prompt_toolkit.completion import WordCompleter
|
||||||
|
|
@ -75,20 +76,13 @@ class HafasClient:
|
||||||
# - Departure/arrival time: departure["stbStop"]["dTimeS"] or ["aTimeS"]
|
# - Departure/arrival time: departure["stbStop"]["dTimeS"] or ["aTimeS"]
|
||||||
departures.append({
|
departures.append({
|
||||||
"name": departure.get("dirTxt"),
|
"name": departure.get("dirTxt"),
|
||||||
"line": (
|
"line": re.search(r'#ZB#([^#]+)', departure.get("jid")).group(1).strip(),
|
||||||
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")
|
|
||||||
),
|
|
||||||
"departure_time": self._format_time(stop.get(time_key)),
|
"departure_time": self._format_time(stop.get(time_key)),
|
||||||
"departure_time_raw": 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": self._format_time(stop.get(time_key_real)),
|
||||||
"departure_time_real_raw": stop.get(time_key_real),
|
"departure_time_real_raw": stop.get(time_key_real),
|
||||||
"jid": departure.get("jid"),
|
"jid": departure.get("jid"),
|
||||||
"raw": departure,
|
# "raw": departure,
|
||||||
})
|
})
|
||||||
|
|
||||||
return departures
|
return departures
|
||||||
|
|
@ -114,13 +108,19 @@ class HafasClient:
|
||||||
trip = self.getTrip(departures[0]["jid"])
|
trip = self.getTrip(departures[0]["jid"])
|
||||||
__import__('pprint').pprint(trip)
|
__import__('pprint').pprint(trip)
|
||||||
|
|
||||||
def moniterTest(self):
|
def monitorTest(self):
|
||||||
stationInput = input("Enter Station Name: ")
|
stationInput = input("Enter Station Name: ")
|
||||||
station = self.getStationNames(stationInput)
|
station = self.getStationNames(stationInput)
|
||||||
print(station)
|
print(station)
|
||||||
# departures = self.getArrDep(station[0][1], arrdep="DEP", count=1)
|
# departures = self.getArrDep(station[0][1], arrdep="DEP", count=1)
|
||||||
departures = self.arrDepRequest(station[0][1], arrdep="DEP", count=1)
|
print("\n)------------------\n")
|
||||||
print(departures)
|
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"]
|
# streq = self.stationRequest(station)["svcResL"][0]["res"]["match"]["locL"]
|
||||||
|
|
@ -140,4 +140,4 @@ class HafasClient:
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
client = HafasClient()
|
client = HafasClient()
|
||||||
# client.runTests()
|
# client.runTests()
|
||||||
client.moniterTest()
|
client.monitorTest()
|
||||||
|
|
|
||||||
|
|
@ -90,13 +90,13 @@ def run_station_monitor(hafas: backend.HafasClient | None = None):
|
||||||
arrivals = hafas.getArrDep(station_id, arrdep="ARR", count=5)
|
arrivals = hafas.getArrDep(station_id, arrdep="ARR", count=5)
|
||||||
arrivalBuffer.text = (
|
arrivalBuffer.text = (
|
||||||
f"Ankünfte für {station_name}:\n"
|
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)
|
departures = hafas.getArrDep(station_id, arrdep="DEP", count=5)
|
||||||
departureBuffer.text = (
|
departureBuffer.text = (
|
||||||
f"Abfahrten für {station_name}:\n"
|
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 = ""
|
userinputBuffer.text = ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue