diff --git a/pyrmv/classes/Journey.py b/pyrmv/classes/Journey.py index a01cf8c..7efb2de 100644 --- a/pyrmv/classes/Journey.py +++ b/pyrmv/classes/Journey.py @@ -1,2 +1,18 @@ +from pyrmv.classes.Stop import Stop +from pyrmv.classes.Message import Message + class Journey(): - pass \ No newline at end of file + def __init__(self, data: dict): + self.stops = [] + self.direction = data["Directions"]["Direction"][0]["value"] + self.direction_flag = data["Directions"]["Direction"][0]["flag"] + self.messages = [] + + for stop in data["Stops"]["Stop"]: + self.stops.append(Stop(stop)) + + for message in data["Messages"]["Message"]: + self.messages.append(Message(message)) + + 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})" \ No newline at end of file diff --git a/pyrmv/classes/Stop.py b/pyrmv/classes/Stop.py index faa30ef..fbd1d77 100644 --- a/pyrmv/classes/Stop.py +++ b/pyrmv/classes/Stop.py @@ -8,17 +8,35 @@ class Stop(): self.name = data["name"] self.id = data["id"] + if "extId" in data: self.ext_id = data["extId"] else: self.ext_id = None + if "description" in data: self.description = data["description"] else: self.description = None + self.lon = data["lon"] self.lat = data["lat"] + if "routeIdx" in data: + self.route_index = data["routeIdx"] + else: + self.route_index = None + + if "arrTrack" in data: + self.track_arrival = data["arrTrack"] + else: + self.track_arrival = None + + if "depTrack" in data: + self.track_departure = data["depTrack"] + else: + self.track_departure = None + def __str__(self) -> str: return f"Stop {self.name} at {self.lon}, {self.lat}" diff --git a/pyrmv/methods/journey_detail.py b/pyrmv/methods/journey_detail.py index a540e13..a85d557 100644 --- a/pyrmv/methods/journey_detail.py +++ b/pyrmv/methods/journey_detail.py @@ -1,5 +1,39 @@ +from datetime import datetime +from typing import Union +from pyrmv.classes.Journey import Journey from pyrmv.errors.not_ready import NotReadyYetError +from pyrmv.enums.rt_mode import RealTimeMode +from pyrmv.raw.journey_detail import journey_detail as raw_journey_detail +from pyrmv.utility.find_exception import find_exception +try: + from typing import Literal +except ImportError: + from typing_extensions import Literal -def journey_detail(): - raise NotReadyYetError() \ No newline at end of file +def journey_detail( + + access_id: str, + id: str, + date: Union[str, datetime] = None, + real_time_mode: Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT] = None, + from_id: str = None, + from_index: int = None, + to_id: str = None, + to_index: int = None + ): + + journey_raw = raw_journey_detail( + accessId=access_id, + id=id, + date=date, + rtMode=real_time_mode.code, + fromId=from_id, + fromIdx=from_index, + toId=to_id, + toIdx=to_index + ) + + find_exception(journey_raw) + + return Journey(journey_raw) \ No newline at end of file diff --git a/pyrmv/raw/journey_detail.py b/pyrmv/raw/journey_detail.py index 2b6b007..fb9de14 100644 --- a/pyrmv/raw/journey_detail.py +++ b/pyrmv/raw/journey_detail.py @@ -57,7 +57,10 @@ def journey_detail(accessId: str, payload = {} for var, val in locals().items(): - if str(var) not in ["json", "headers", "payload"]: + if str(var) == "rtMode": + if val != None: + payload["rtMode"] = val.upper() + elif str(var) not in ["json", "headers", "payload"]: if val != None: payload[str(var)] = val