From 8fc4b573807dbcbcd4f3f374b1197b9ff3297446 Mon Sep 17 00:00:00 2001 From: chrissy Date: Fri, 11 Sep 2026 10:09:23 +0200 Subject: [PATCH] aktualisiert --- travelInfo.py | 74 +++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/travelInfo.py b/travelInfo.py index 4b9d1ff..594cf5c 100755 --- a/travelInfo.py +++ b/travelInfo.py @@ -38,6 +38,8 @@ ssid_regio = [ "alex WiFi", "trilex WiFi", "DBLounge", + "48WEc-024 5GHz", + "Pendolino_WiFi", ] @@ -76,11 +78,16 @@ def get_api_cd(): "http://cdwifi.cz/portal/api/vehicle/realtime", timeout=5 ) statusDataCD = statusDataCD_response.json() + tripDataCD_response = requests.get( + "http://cdwifi.cz/portal/api/timetable/connexion/current", timeout=5 + ) + tripDataCD = tripDataCD_response.json() return 1 except requests.exceptions.RequestException: return 0 + # Look for the current SSID. Replace wlp2s0 with the real name of your wifi interface and check, that the path to iwlist is correct (just type 'which iwlist' in the terminal) def get_ssid(): try: @@ -115,7 +122,7 @@ def get_speed_cd(): # Figure out, whats the next station and filter the output for this. def get_next_db(): - try: + try: if tripData["trip"]["stopInfo"] == None: return "No TripInfo" @@ -140,46 +147,51 @@ def get_next_db(): + ") @ " + nextStationTrack ) - except: + except: tripinfo = "Unavail" return tripinfo def get_next_tl(): try: - if len(tripDataTl["intermediateStops"])==0: - tripinfo = tripDataTl["toStation"]["name"] + if len(tripDataTl["intermediateStops"]) == 0: + tripinfo = tripDataTl["toStation"]["name"] else: for i in tripDataTl["intermediateStops"]: - if i["realArrival"] == None: - nextStopArrival=i["scheduledArrival"] - else: - nextStopArrival=i["realArrival"] - + nextStopArrival = i["realArrival"] or i["scheduledArrival"] + if nextStopArrival is None: + continue if nextStopArrival >= time.time(): nextStationName = i["name"] uScheduledTime = i["scheduledArrival"] uActualTime = i["realArrival"] - if uActualTime == None: - arrivalDelay="-" + if uActualTime == None: + arrivalDelay = "-" else: - arrivalDelay = "{:+.0f}".format(((uActualTime - uScheduledTime) / 60)) - - arrivalTime = datetime.fromtimestamp(nextStopArrival, tz=timezone).strftime( - "%H:%M" - ) + arrivalDelay = "{:+.0f}".format( + ((uActualTime - uScheduledTime) / 60) + ) + + arrivalTime = datetime.fromtimestamp( + nextStopArrival, tz=timezone + ).strftime("%H:%M") tripinfo = ( nextStationName + " " + arrivalTime + " (" + arrivalDelay + ")" ) break else: - next - tripinfo = tripDataTl["toStation"]["name"] + tripinfo = tripDataTl["toStation"]["name"] except: tripinfo = tripDataTl["toStation"]["name"] return tripinfo +def get_next_cd(): + tripinfo = "" + + + return tripinfo + # Get the Trainnumber and final station of your current train def get_trainInfo_db(): if tripData["trip"]["trainType"] == None: @@ -188,23 +200,26 @@ def get_trainInfo_db(): trainType = tripData["trip"]["trainType"] or "" trainNumber = tripData["trip"]["vzn"] or "" finalStationName = tripData["trip"]["stopInfo"]["finalStationName"] or "" - return trainType + " " + trainNumber + return trainType + " " + trainNumber + # Get the Trainnumber and final station of your current travelynx trip def get_trainInfo_tl(): checkin_tl() - trainType = tripDataTl["train"]["type"] or "" + trainType = tripDataTl["train"]["type"] or "" trainNumber = tripDataTl["train"]["no"] or "" - #fromStationName = tripDataTl["fromStation"]["name"] - fromStationDS100=tripDataTl['fromStation']['ds100'] or "" - toStationDS100=tripDataTl['toStation']['ds100'] or "" + # fromStationName = tripDataTl["fromStation"]["name"] + fromStationDS100 = tripDataTl["fromStation"]["ds100"] or "" + toStationDS100 = tripDataTl["toStation"]["ds100"] or "" toStationName = tripDataTl["toStation"]["name"] or "" toStationTrack = tripDataTl["toStation"]["platform"] or "" uScheduledTime = tripDataTl["toStation"]["scheduledTime"] or "" uActualTime = tripDataTl["toStation"]["realTime"] or "" arrivalDelay = "{:+.0f}".format(((uActualTime - uScheduledTime) / 60)) or "" - arrivalTime = datetime.fromtimestamp(uActualTime, tz=timezone).strftime("%H:%M") or "" - nextStop=get_next_tl() + arrivalTime = ( + datetime.fromtimestamp(uActualTime, tz=timezone).strftime("%H:%M") or "" + ) + nextStop = get_next_tl() return ( trainType + " " @@ -222,7 +237,6 @@ def get_trainInfo_tl(): ) - def checkin_tl(): if tripDataTl["checkedIn"] == False: sys.exit() @@ -260,12 +274,8 @@ def main(): re.sub( r"\s+", " ", - get_trainInfo_tl() - + " | " - + "SPEED: " - + get_speed_cd() - + " km/h" - ) + get_trainInfo_tl() + " | " + "SPEED: " + get_speed_cd() + " km/h", + ) )