Compare commits

..

No commits in common. "428442d1cb15992c89584e4d88d4d6e6a16265ae" and "8cb28e90302db1ebd091d810e8bab51267aac0c4" have entirely different histories.

5 changed files with 29 additions and 17 deletions

View File

@ -3,7 +3,6 @@ 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"])

View File

@ -9,12 +9,10 @@ class Leg():
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"]
@ -24,9 +22,13 @@ class Leg():
else:
self.direction = None
self.messages = []
for message in data["Messages"]["Message"]:
self.messages.append(Message(message))
if "Messages" in data:
messages = []
for message in data["Messages"]["Message"]:
messages.append(Message(message))
self.messages = messages
else:
self.messages = None
if "number" in data:
self.number = data["number"]

View File

@ -32,16 +32,18 @@ class Message():
def __init__(self, data: dict) -> None:
self.affected_stops = []
affected_stops = []
for stop in data["affectedStops"]["StopLocation"]:
self.affected_stops.append(Stop(stop))
affected_stops.append(Stop(stop))
self.affected_stops = affected_stops
self.valid_from_stop = Stop(data["validFromStop"])
self.valid_to_stop = Stop(data["validToStop"])
self.channels = []
channels = []
for channel in data["channel"]:
self.channels.append(Channel(channel))
channels.append(Channel(channel))
self.channels = channels
self.id = data["id"]
self.active = data["act"]

View File

@ -4,7 +4,6 @@ from datetime import datetime
class Stop():
def __init__(self, data: dict):
self.name = data["name"]
self.id = data["id"]
if "extId" in data:
@ -14,17 +13,29 @@ class Stop():
self.lon = data["lon"]
self.lat = data["lat"]
def get_id(self) -> str:
if self.id != None:
return self.id
elif self.ext_id != None:
return self.ext_id
elif self.name != None:
return self.name
else:
return f"{self.lon}, {self.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 = datetime.strptime(data["date"], "%Y-%m-%d")
self.time = datetime.strptime(data["time"], "%H:%M:%S")
super().__init__(data)
def get_id(self) -> str:
return super().get_id()
def __str__(self) -> str:
return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time.time()} {self.date.date()}"

View File

@ -5,15 +5,13 @@ 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"])
self.legs = []
legs = []
for leg in data["LegList"]["Leg"]:
self.legs.append(Leg(leg))
legs.append(Leg(leg))
self.legs = legs
self.calculation = data["calculation"]
self.index = data["idx"]
self.id = data["tripId"]