Skip to content

Commit

Permalink
Fix failing on "CORUÑA E.A." realtime and others
Browse files Browse the repository at this point in the history
  • Loading branch information
peprolinbot committed Oct 12, 2024
1 parent edf4ba8 commit 5b7b5e5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions busGal_api/transport/expeditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,17 +379,20 @@ def element_to_dict(element):
if len(child) > 0:
result[tag_name] = element_to_dict(child)
else:
result[tag_name] = int(
child.text) if child.text.isdigit() else child.text
try:
result[tag_name] = int(
child.text)
except (ValueError, TypeError):
result[tag_name] = child.text

return result

root = ET.fromstring(bytes(response.text, encoding='utf-8'))

expeditions = {}
for descendant in root.iter("{http://www.siri.org.uk/siri}MonitoredVehicleJourney"):
elem_dict = element_to_dict(descendant)
expeditions[elem_dict["CourseOfJourneyRef"]] = elem_dict
for journey in root.iter("{http://www.siri.org.uk/siri}MonitoredVehicleJourney"):
journey_data = element_to_dict(journey)
expeditions[journey_data["CourseOfJourneyRef"]] = journey_data

return expeditions

Expand Down

0 comments on commit 5b7b5e5

Please sign in to comment.