Empty attributes now return list instead of None

This commit is contained in:
Profitroll 2022-09-24 12:08:16 +02:00
parent 8cb28e9030
commit deb49e174b
3 changed files with 14 additions and 16 deletions

View File

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

View File

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

View File

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