diff --git a/travelInfo.py b/travelInfo.py index f5f2132..28a717e 100755 --- a/travelInfo.py +++ b/travelInfo.py @@ -29,29 +29,31 @@ def get_api_db(): # Request data from travelynx def get_api_tl(): global tripDataTl - tripDataTl_response = requests.get("https://travelynx.de/api/v1/status/[YOUR API TOKEN", timeout=5) + tripDataTl_response = requests.get("https://travelynx.de/api/v1/status/[YOUR API TOKEN]", timeout=5) tripDataTl = tripDataTl_response.json() # 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(): - - scanoutput = check_output(["/usr/sbin/iwlist", "wlp2s0", "scan"]) + try: + output = check_output(['/usr/sbin/iwgetid']).decode('utf-8') + ssid=output.split('"')[1] + return ssid + except: + pass - for line in scanoutput.split(): - line = line.decode("utf-8") - if line[:5] == "ESSID": - ssid = line.split('"')[1] - return ssid # Get Speed from ICE-Portal def get_speed_db(): - if statusData["speed"]==None: - return "No Speed" - else: + try: speed= str(statusData["speed"]) + if speed==None: + speed="No Speed" return speed + except: + return "No Speed" + # Figure out, whats the next station and filter the output for this. def get_next_db(): if tripData["trip"]["stopInfo"] == None : @@ -78,6 +80,11 @@ def get_next_tl(): arrivalDelay="{:+.0f}".format(((uActualTime-uScheduledTime)/60)) arrivalTime = datetime.fromtimestamp(uActualTime, tz=timezone).strftime('%H:%M') break + else: + nextStationName=tripDataTl['toStation']['name'] + arrivalTime=None + arrivalDelay=None + break tripinfo = nextStationName+" "+arrivalTime+" ("+arrivalDelay+")" #tripinfo = nextStationName+" "+ arrivalTime+" ("+ arrivalDelay+") @ "+ nextStationTrack return tripinfo