diff --git a/pyrmv/classes/Gis.py b/pyrmv/classes/Gis.py new file mode 100644 index 0000000..bb3873b --- /dev/null +++ b/pyrmv/classes/Gis.py @@ -0,0 +1,8 @@ +from isodate import parse_duration + +class Gis(): + def __init__(self, ref: str, route: dict): + self.ref = ref + self.dist = route["dist"] + self.duration = parse_duration(route["durS"]) + self.geo = route["dirGeo"] \ No newline at end of file diff --git a/pyrmv/classes/Journey.py b/pyrmv/classes/Journey.py new file mode 100644 index 0000000..a01cf8c --- /dev/null +++ b/pyrmv/classes/Journey.py @@ -0,0 +1,2 @@ +class Journey(): + pass \ No newline at end of file diff --git a/pyrmv/classes/Leg.py b/pyrmv/classes/Leg.py new file mode 100644 index 0000000..cc768a4 --- /dev/null +++ b/pyrmv/classes/Leg.py @@ -0,0 +1,20 @@ +from pyrmv.classes.Gis import Gis +from pyrmv.classes.Stop import StopTrip +from isodate import parse_duration + +class Leg(): + def __init__(self, data: dict): + self.origin = StopTrip(data["Origin"]) + self.destination = StopTrip(data["Destination"]) + if "GisRef" in data: + self.gis = Gis(data["GisRef"]["ref"], data["GisRoute"]) + else: + self.gis = None + self.index = data["idx"] + self.name = data["name"] + self.type = data["type"] + self.duration = parse_duration(data["duration"]) + if "dist" in data: + self.distance = data["dist"] + else: + self.distance = None \ No newline at end of file diff --git a/pyrmv/classes/Product.py b/pyrmv/classes/Product.py new file mode 100644 index 0000000..20a631e --- /dev/null +++ b/pyrmv/classes/Product.py @@ -0,0 +1,3 @@ +class Product(): + def __init__(self): + pass \ No newline at end of file diff --git a/pyrmv/classes/Stop.py b/pyrmv/classes/Stop.py new file mode 100644 index 0000000..a7cb75b --- /dev/null +++ b/pyrmv/classes/Stop.py @@ -0,0 +1,26 @@ +from time import strptime + + +class Stop(): + def __init__(self, data: dict): + self.name = data["name"] + self.id = data["id"] + if "extId" in data: + self.ext_id = data["extId"] + else: + self.ext_id = None + self.lon = data["lon"] + self.lat = data["lat"] + + def __str__(self) -> str: + return f"Stop {self.name} at {self.lon}, {self.lat}" + +class StopTrip(Stop): + def __init__(self, data: dict): + self.type = data["type"] + self.date = strptime(data["date"], "%Y-%m-%d") + self.time = strptime(data["time"], "%H:%M:%S") + super().__init__(data) + + def __str__(self) -> str: + return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time} {self.date}" \ No newline at end of file diff --git a/pyrmv/classes/Trip.py b/pyrmv/classes/Trip.py new file mode 100644 index 0000000..eb35a3a --- /dev/null +++ b/pyrmv/classes/Trip.py @@ -0,0 +1,25 @@ +from pyrmv.classes.Leg import Leg +from pyrmv.classes.Stop import StopTrip +from isodate import parse_duration + +class Trip(): + + def __init__(self, data: dict): + self.raw_data = data + self.origin = StopTrip(data["Origin"]) + self.destination = StopTrip(data["Destination"]) + legs = [] + for leg in data["LegList"]["Leg"]: + legs.append(Leg(leg)) + self.legs = legs + 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" \ No newline at end of file