making it readable
This commit is contained in:
parent
bd12b740d1
commit
9dde4fd3d9
35
efa.py
35
efa.py
|
|
@ -36,12 +36,14 @@ def selectStop(stops):
|
||||||
def getMaxLength(elem, array):
|
def getMaxLength(elem, array):
|
||||||
return max(map(lambda f: len(f[elem]), array))
|
return max(map(lambda f: len(f[elem]), array))
|
||||||
|
|
||||||
|
|
||||||
def getDepartures(stopId):
|
def getDepartures(stopId):
|
||||||
url = "https://webapi.vvo-online.de/dm"
|
url = "https://webapi.vvo-online.de/dm"
|
||||||
myobj = {"stopid": stopId}
|
myobj = {"stopid": stopId}
|
||||||
|
now=datetime.datetime.now()
|
||||||
x = requests.post(url, json=myobj)
|
x = requests.post(url, json=myobj)
|
||||||
x = x.json()
|
x = x.json()
|
||||||
|
print(f"Departures for {x['Name']}, {x['Place']}:\n ")
|
||||||
for Departure in x["Departures"]:
|
for Departure in x["Departures"]:
|
||||||
MotType = Departure["Mot"]
|
MotType = Departure["Mot"]
|
||||||
LineName = Departure["LineName"]
|
LineName = Departure["LineName"]
|
||||||
|
|
@ -55,16 +57,20 @@ def getDepartures(stopId):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
RealTime = None
|
RealTime = None
|
||||||
if "State" in Departure and Departure["State"] == "Delayed":
|
if "State" in Departure and Departure["State"] == "Delayed":
|
||||||
delay = RealTime - ScheduledTime
|
delay = (RealTime - ScheduledTime)
|
||||||
|
delay=delay.seconds/60
|
||||||
else:
|
else:
|
||||||
delay = ""
|
delay = ""
|
||||||
print(f"{MotType:>{getMaxLength("Mot",x["Departures"])}s} "
|
DepartureTime =(RealTime or ScheduledTime).strftime("%H:%M")
|
||||||
f"{LineName:>{getMaxLength("LineName",x['Departures'])}s} "
|
relativeDeparture = int(((RealTime or ScheduledTime) - now).seconds/60)
|
||||||
f"{Direction:{getMaxLength("Direction",x["Departures"])}s} "
|
print(
|
||||||
f"{ScheduledTime} "
|
f"{MotType:>{getMaxLength("Mot",x["Departures"])}s} "
|
||||||
f"{RealTime} "
|
f"{LineName:>{getMaxLength("LineName",x['Departures'])}s} "
|
||||||
f"{delay} "
|
f"{Direction:{getMaxLength("Direction",x["Departures"])}s} "
|
||||||
|
f"{DepartureTime} "
|
||||||
|
f"{relativeDeparture:>3} "
|
||||||
|
f"{delay} "
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -80,6 +86,17 @@ if __name__ == "__main__":
|
||||||
parser.add_argument("stopQuery") # positional argument
|
parser.add_argument("stopQuery") # positional argument
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog="VVO EFA Haltestellenauskunft", description="Miau!", epilog="=^.^="
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument("stopQuery") # positional argument
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
stop = searchStop(args.stopQuery)
|
stop = searchStop(args.stopQuery)
|
||||||
|
|
||||||
if len(stop) > 1:
|
if len(stop) > 1:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue