Skip to content

Commit

Permalink
add more data checks
Browse files Browse the repository at this point in the history
  • Loading branch information
drosoCode committed Dec 18, 2022
1 parent 5f9fa3d commit d3701ea
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions idfm_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ class TrafficData:
def from_json(data: dict):
try:
dir = data["MonitoredVehicleJourney"]["DirectionName"][0]["value"]
except KeyError:
except (KeyError, IndexError):
dir = data["MonitoredVehicleJourney"]["DestinationName"][0]["value"]

try:
note = data["MonitoredVehicleJourney"]["JourneyNote"][0]["value"]
except KeyError:
except (KeyError, IndexError):
note = ""

sch = None
Expand All @@ -135,9 +135,9 @@ def from_json(data: dict):
except KeyError:
plat = ""

if "ArrivalStatus" in data["MonitoredVehicleJourney"]["MonitoredCall"]:
if "ArrivalStatus" in data["MonitoredVehicleJourney"]["MonitoredCall"] and data["MonitoredVehicleJourney"]["MonitoredCall"]["ArrivalStatus"] != "":
status = TransportStatus(data["MonitoredVehicleJourney"]["MonitoredCall"]["ArrivalStatus"])
elif "DepartureStatus" in data["MonitoredVehicleJourney"]["MonitoredCall"]:
elif "DepartureStatus" in data["MonitoredVehicleJourney"]["MonitoredCall"] and data["MonitoredVehicleJourney"]["MonitoredCall"]["DepartureStatus"] != "":
status = TransportStatus(data["MonitoredVehicleJourney"]["MonitoredCall"]["DepartureStatus"])
else:
status = TransportStatus.UNKNOWN
Expand Down

0 comments on commit d3701ea

Please sign in to comment.