making it more modular...
This commit is contained in:
parent
e5cfcc822f
commit
151e9b13cd
|
|
@ -9,6 +9,16 @@ from datetime import datetime
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
timezone = pytz.timezone('Europe/Berlin')
|
timezone = pytz.timezone('Europe/Berlin')
|
||||||
|
statusData = None
|
||||||
|
tripData = None
|
||||||
|
|
||||||
|
def get_api_db():
|
||||||
|
global statusData
|
||||||
|
global tripData
|
||||||
|
statusData_response = get("https://iceportal.de/api1/rs/status")
|
||||||
|
statusData = statusData_response.json()
|
||||||
|
tripData_response = get("https://iceportal.de/api1/rs/tripInfo/trip")
|
||||||
|
tripData = tripData_response.json()
|
||||||
|
|
||||||
def get_ssid():
|
def get_ssid():
|
||||||
|
|
||||||
|
|
@ -22,19 +32,12 @@ def get_ssid():
|
||||||
|
|
||||||
# Get Speed from ICE-Portal
|
# Get Speed from ICE-Portal
|
||||||
def get_speed_db():
|
def get_speed_db():
|
||||||
rs = "https://iceportal.de/api1/rs/status"
|
speed= str(statusData["speed"])
|
||||||
response = get(rs)
|
|
||||||
data = response.json()
|
|
||||||
speed= str(data["speed"])
|
|
||||||
return speed
|
return speed
|
||||||
|
|
||||||
def get_next_db():
|
def get_next_db():
|
||||||
rs = "https://iceportal.de/api1/rs/tripInfo/trip/"
|
next_stop=tripData["trip"]["stopInfo"]["actualNext"]
|
||||||
response = get(rs)
|
for i in tripData['trip']['stops']:
|
||||||
data = response.json()
|
|
||||||
next_stop=data["trip"]["stopInfo"]["actualNext"]
|
|
||||||
|
|
||||||
for i in data['trip']['stops']:
|
|
||||||
if i['station']['evaNr'] == next_stop:
|
if i['station']['evaNr'] == next_stop:
|
||||||
nextStationName = i['station']['name']
|
nextStationName = i['station']['name']
|
||||||
arrivalDelay = i['timetable']['arrivalDelay']
|
arrivalDelay = i['timetable']['arrivalDelay']
|
||||||
|
|
@ -45,16 +48,14 @@ def get_next_db():
|
||||||
return tripinfo
|
return tripinfo
|
||||||
|
|
||||||
def get_trainInfo_db():
|
def get_trainInfo_db():
|
||||||
rs = "https://iceportal.de/api1/rs/tripInfo/trip/"
|
trainType = tripData["trip"]["trainType"]
|
||||||
response = get(rs)
|
trainNumber = tripData["trip"]["vzn"]
|
||||||
data = response.json()
|
finalStationName = tripData["trip"]["stopInfo"]["finalStationName"]
|
||||||
trainType = data["trip"]["trainType"]
|
|
||||||
trainNumber = data["trip"]["vzn"]
|
|
||||||
finalStationName = data["trip"]["stopInfo"]["finalStationName"]
|
|
||||||
return trainType+" "+trainNumber+" "+ finalStationName
|
return trainType+" "+trainNumber+" "+ finalStationName
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if get_ssid() == "WIFIonICE":
|
if get_ssid() == "WIFIonICE":
|
||||||
|
get_api_db()
|
||||||
print(get_trainInfo_db()+" | "+"SPEED: "+get_speed_db()+" km/h | "+"NEXT: "+get_next_db())
|
print(get_trainInfo_db()+" | "+"SPEED: "+get_speed_db()+" km/h | "+"NEXT: "+get_next_db())
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue