PythonRMV/pyrmv/classes/Trip.py

27 lines
1007 B
Python
Raw Normal View History

2022-09-23 23:58:45 +03:00
from pyrmv.classes.Leg import Leg
from pyrmv.classes.Stop import StopTrip
from isodate import parse_duration
class Trip():
def __init__(self, data: dict):
2022-09-23 23:58:45 +03:00
self.raw_data = data
self.origin = StopTrip(data["Origin"])
self.destination = StopTrip(data["Destination"])
self.legs = []
2022-09-23 23:58:45 +03:00
for leg in data["LegList"]["Leg"]:
self.legs.append(Leg(leg))
2022-09-23 23:58:45 +03:00
self.calculation = data["calculation"]
self.index = data["idx"]
self.id = data["tripId"]
self.ctx_recon = data["ctxRecon"]
self.duration = parse_duration(data["duration"])
self.real_time_duration = parse_duration(data["rtDuration"])
self.checksum = data["checksum"]
self.transfer_count = data["transferCount"]
def __str__(self) -> str:
return f"Trip from {self.origin.name} to {self.destination.name} lasting {self.duration} ({self.real_time_duration}) with {len(self.legs)} legs and {self.transfer_count} transfers"