infotbm/src/main.py

44 lines
1.9 KiB
Python
Raw Normal View History

2022-04-28 12:03:51 +02:00
import sys
2022-04-30 01:43:20 +02:00
from tbm_api.stop_area import *
from tbm_api.stop import *
from tbm_api.stop_route import StopRoute
2022-04-28 12:03:51 +02:00
from datetime import datetime
2022-04-30 01:43:20 +02:00
2022-04-28 12:03:51 +02:00
if __name__ == "__main__":
for word in sys.argv[1:]:
2022-04-30 01:43:20 +02:00
for area in get_stop_areas_by_name(word):
stop = get_stop_by_id(area.getId())
for stopPoint in stop.getStopPoints():
for route in stopPoint.getRoutes():
if "Tram" in route.getLineName():
stopRoute = StopRoute(stopPoint.getId(), route.getId())
line = stopRoute.get_line()
for vehicule in line.get_vehicles():
2022-04-28 12:03:51 +02:00
v = line.get_vehicle(vehicule)
2022-04-30 01:43:20 +02:00
if v.getRealtime():
2022-04-28 12:03:51 +02:00
print(
2022-04-30 01:43:20 +02:00
str(v.getWaitTimeText())
2022-04-28 12:03:51 +02:00
+ " ("
2022-04-30 01:43:20 +02:00
+ datetime.fromtimestamp(v.getArrival()).strftime(
2022-04-28 12:03:51 +02:00
"%H:%M"
)
+ ") → "
2022-04-30 01:43:20 +02:00
+ v.getDestination()
+ ", Curr location: "
+ str(v.getLocation())
2022-04-28 12:03:51 +02:00
)
else:
print(
"~"
2022-04-30 01:43:20 +02:00
+ str(v.getWaitTimeText())
2022-04-28 12:03:51 +02:00
+ " ("
2022-04-30 01:43:20 +02:00
+ datetime.fromtimestamp(v.getArrival()).strftime(
2022-04-28 12:03:51 +02:00
"%H:%M"
)
+ ") → "
2022-04-30 01:43:20 +02:00
+ v.getDestination()
+ ", Curr location: "
+ str(v.getLocation())
2022-04-28 12:03:51 +02:00
)