PythonRMV/pyrmv/classes/Journey.py

22 lines
793 B
Python
Raw Permalink Normal View History

2022-10-06 12:36:08 +03:00
from pyrmv.classes.Stop import Stop
from pyrmv.classes.Message import Message
2022-09-23 23:58:45 +03:00
class Journey():
2022-10-06 13:09:30 +03:00
"""Journey object."""
2022-10-06 12:36:08 +03:00
def __init__(self, data: dict):
self.stops = []
2022-10-07 12:35:02 +03:00
self.ref = data["ref"]
2022-10-06 12:36:08 +03:00
self.direction = data["Directions"]["Direction"][0]["value"]
self.direction_flag = data["Directions"]["Direction"][0]["flag"]
self.messages = []
2023-11-19 13:19:31 +02:00
self.stops.extend(Stop(stop) for stop in data["Stops"]["Stop"])
2022-10-06 12:36:08 +03:00
2023-11-19 13:19:31 +02:00
if "Messages" in data:
self.messages.extend(
Message(message) for message in data["Messages"]["Message"]
)
2022-10-06 12:36:08 +03:00
def __str__(self) -> str:
return f"Journey with total of {len(self.stops)} stops and {len(self.messages)} messages heading {self.direction} ({self.direction_flag})"