2022-09-23 23:58:45 +03:00
|
|
|
from pyrmv.classes.Gis import Gis
|
2022-09-24 12:40:38 +03:00
|
|
|
from pyrmv.classes.Message import Message
|
2022-09-23 23:58:45 +03:00
|
|
|
from pyrmv.classes.Stop import StopTrip
|
|
|
|
from isodate import parse_duration
|
|
|
|
|
|
|
|
class Leg():
|
2022-10-05 13:17:51 +03:00
|
|
|
"""Trip leg object."""
|
2022-09-24 12:40:38 +03:00
|
|
|
|
2022-09-23 23:58:45 +03:00
|
|
|
def __init__(self, data: dict):
|
2022-09-24 12:40:38 +03:00
|
|
|
|
2022-09-23 23:58:45 +03:00
|
|
|
self.origin = StopTrip(data["Origin"])
|
|
|
|
self.destination = StopTrip(data["Destination"])
|
2022-09-24 13:08:16 +03:00
|
|
|
|
2022-09-23 23:58:45 +03:00
|
|
|
if "GisRef" in data:
|
|
|
|
self.gis = Gis(data["GisRef"]["ref"], data["GisRoute"])
|
|
|
|
else:
|
|
|
|
self.gis = None
|
2022-09-24 13:58:29 +03:00
|
|
|
|
2022-09-23 23:58:45 +03:00
|
|
|
self.index = data["idx"]
|
|
|
|
self.name = data["name"]
|
|
|
|
self.type = data["type"]
|
2022-09-24 12:40:38 +03:00
|
|
|
|
|
|
|
if "direction" in data:
|
|
|
|
self.direction = data["direction"]
|
|
|
|
else:
|
|
|
|
self.direction = None
|
|
|
|
|
2022-09-24 13:08:16 +03:00
|
|
|
self.messages = []
|
2022-09-24 13:58:29 +03:00
|
|
|
if "Messages" in data:
|
|
|
|
for message in data["Messages"]["Message"]:
|
|
|
|
self.messages.append(Message(message))
|
2022-09-24 12:40:38 +03:00
|
|
|
|
|
|
|
if "number" in data:
|
|
|
|
self.number = data["number"]
|
|
|
|
else:
|
|
|
|
self.number = None
|
|
|
|
|
2022-09-23 23:58:45 +03:00
|
|
|
self.duration = parse_duration(data["duration"])
|
2022-09-24 12:40:38 +03:00
|
|
|
|
2022-09-23 23:58:45 +03:00
|
|
|
if "dist" in data:
|
|
|
|
self.distance = data["dist"]
|
|
|
|
else:
|
|
|
|
self.distance = None
|