Created some classes
This commit is contained in:
parent
45a59ff6f6
commit
ab02e13825
8
pyrmv/classes/Gis.py
Normal file
8
pyrmv/classes/Gis.py
Normal file
@ -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"]
|
2
pyrmv/classes/Journey.py
Normal file
2
pyrmv/classes/Journey.py
Normal file
@ -0,0 +1,2 @@
|
||||
class Journey():
|
||||
pass
|
20
pyrmv/classes/Leg.py
Normal file
20
pyrmv/classes/Leg.py
Normal file
@ -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
|
3
pyrmv/classes/Product.py
Normal file
3
pyrmv/classes/Product.py
Normal file
@ -0,0 +1,3 @@
|
||||
class Product():
|
||||
def __init__(self):
|
||||
pass
|
26
pyrmv/classes/Stop.py
Normal file
26
pyrmv/classes/Stop.py
Normal file
@ -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}"
|
25
pyrmv/classes/Trip.py
Normal file
25
pyrmv/classes/Trip.py
Normal file
@ -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"
|
Loading…
Reference in New Issue
Block a user