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):
|
||||
return max(map(lambda f: len(f[elem]), array))
|
||||
|
||||
|
||||
def getDepartures(stopId):
|
||||
url = "https://webapi.vvo-online.de/dm"
|
||||
myobj = {"stopid": stopId}
|
||||
|
||||
now=datetime.datetime.now()
|
||||
x = requests.post(url, json=myobj)
|
||||
x = x.json()
|
||||
print(f"Departures for {x['Name']}, {x['Place']}:\n ")
|
||||
for Departure in x["Departures"]:
|
||||
MotType = Departure["Mot"]
|
||||
LineName = Departure["LineName"]
|
||||
|
|
@ -55,16 +57,20 @@ def getDepartures(stopId):
|
|||
)
|
||||
else:
|
||||
RealTime = None
|
||||
if "State" in Departure and Departure["State"] == "Delayed":
|
||||
delay = RealTime - ScheduledTime
|
||||
if "State" in Departure and Departure["State"] == "Delayed":
|
||||
delay = (RealTime - ScheduledTime)
|
||||
delay=delay.seconds/60
|
||||
else:
|
||||
delay = ""
|
||||
print(f"{MotType:>{getMaxLength("Mot",x["Departures"])}s} "
|
||||
f"{LineName:>{getMaxLength("LineName",x['Departures'])}s} "
|
||||
f"{Direction:{getMaxLength("Direction",x["Departures"])}s} "
|
||||
f"{ScheduledTime} "
|
||||
f"{RealTime} "
|
||||
f"{delay} "
|
||||
DepartureTime =(RealTime or ScheduledTime).strftime("%H:%M")
|
||||
relativeDeparture = int(((RealTime or ScheduledTime) - now).seconds/60)
|
||||
print(
|
||||
f"{MotType:>{getMaxLength("Mot",x["Departures"])}s} "
|
||||
f"{LineName:>{getMaxLength("LineName",x['Departures'])}s} "
|
||||
f"{Direction:{getMaxLength("Direction",x["Departures"])}s} "
|
||||
f"{DepartureTime} "
|
||||
f"{relativeDeparture:>3} "
|
||||
f"{delay} "
|
||||
)
|
||||
|
||||
return
|
||||
|
|
@ -80,6 +86,17 @@ if __name__ == "__main__":
|
|||
parser.add_argument("stopQuery") # positional argument
|
||||
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)
|
||||
|
||||
if len(stop) > 1:
|
||||
|
|
|
|||
Loading…
Reference in New Issue