Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions amarillo/services/importing/matchrider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ def __init__(self, url, http_headers):

@staticmethod
def _extract_stop(stop):
stop_id = f'matchrider:{stop["id"]}' if not stop['id'].startswith('matchrider:') else stop['id']
if stop['id'].startswith('matchrider:'):
stop_id = stop['id']
else:
# if stop id does not start with matchrider:,
# we expect ifopt. However, only station ifopt
# is currently supported, so we chop off trailing parts
stop_id = stop['id'][0:stop['id'].find(':',9)]
stop_name = stop.get('name','-')
arrivalTime = stop.get('arrivalTime')
departureTime = stop.get('departureTime')
if arrivalTime is not None and len(arrivalTime)==5:
Expand All @@ -23,7 +30,7 @@ def _extract_stop(stop):

return StopTime(
id=stop_id,
name=stop['name'],
name=stop_name,
lat=float(stop['lat']),
lon=float(stop['lon']),
arrivalTime=arrivalTime,
Expand All @@ -49,9 +56,6 @@ def _get_data_from_json_response(self, json_response):
for cp in payload:
if self._should_offer_be_ignored(cp):
continue
for stop in cp['stops']:
if 'id' in stop and not stop['id'].startswith('matchrider:'):
stop['id'] = f'matchrider:{stop["id"]}'


filtered_payload.append(cp)
return filtered_payload