Skip to content

Commit

Permalink
feature: use vehicle rental_uri as fallback for station rental_uri
Browse files Browse the repository at this point in the history
  • Loading branch information
hbruch committed May 4, 2023
1 parent d19dfba commit 7d652f6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions cbToGBFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,6 @@ def load_stations(self, datasource):
if station_opening_hours:
station['station_opening_hours'] = station_opening_hours

station_link = elem.get('location_link')
if station_link:
station['rental_uris'] = {
'web': station_link
}

infos[station_id] = station

station_vehicles, station_vehicle_types = self.extract_from_vehicles(elem['items'], station_id, default_last_reported)
Expand All @@ -266,6 +260,19 @@ def load_stations(self, datasource):
'last_reported': default_last_reported
}

station_link = elem.get('location_link')
if station_link:
station['rental_uris'] = {
'web': station_link
}
else:
# in case no station link is provided, we return the link to the first vehicle, if provided
# here we assume, that for most stations, just one vehicle is offered.
# A possible optimization: in case there are more bikes available, prefere a available one
if len(station_vehicles) > 0:
vehicle = next(iter(station_vehicles.values()))
station['rental_uris'] = vehicle['rental_uris']

return list(infos.values()), list(status.values()), vehicle_types, vehicles

class GbfsWriter():
Expand Down

0 comments on commit 7d652f6

Please sign in to comment.