You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
import json
|
|
import requests
|
|
|
|
baseUrl = "https://bsvg.efa.de/bsvagstd/"
|
|
busstop = input("enter busstop name: ")
|
|
|
|
getStr = baseUrl+"XML_DM_REQUEST?"+ \
|
|
"outputFormat=JSON"+ \
|
|
"&stateless=1"+ \
|
|
"&locationServerActive=1" \
|
|
"&type_dm=stop"+ \
|
|
"&name_dm=\""+busstop+"\"" \
|
|
"&mode=direct" \
|
|
"&ptOptionsActive=1" \
|
|
"&useRealtime=1"
|
|
response = requests.get(getStr)
|
|
response.encoding = 'UTF-8'
|
|
|
|
#print(json.dumps(, indent=1))
|
|
|
|
def prettyTime(hour, minute):
|
|
if len(hour) < 2:
|
|
hour="0"+hour
|
|
if len(minute) < 2:
|
|
minute="0"+minute
|
|
return hour+":"+minute
|
|
|
|
if "message" in response.json()['dm']:
|
|
for item in response.json()['dm']['message']:
|
|
if item['name'] == "error" and item['value'] == "name list":
|
|
print("select one of:")
|
|
for point in response.json()['dm']['points']:
|
|
print(point['name'])
|
|
exit()
|
|
|
|
try:
|
|
print("selected: "+response.json()['dm']['points']['point']['name'])
|
|
for item in response.json()['departureList']:
|
|
print(prettyTime(item['dateTime']['hour'], item['dateTime']['minute']), end="\t")
|
|
if "realDateTime" in item:
|
|
print(prettyTime(item['realDateTime']['hour'], item['realDateTime']['minute']), end="\t")
|
|
else:
|
|
print(" ",end='\t')
|
|
print(item['servingLine']['number'], end="\t")
|
|
print(item['servingLine']['direction'])
|
|
except TypeError:
|
|
print("Couldn't get list")
|