diff --git a/CHANGELOG.md b/CHANGELOG.md index b2ee745..0d7eed4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ The changelog lists relevant feature changes between each release. Search GitHub issues and pull requests for smaller issues. +## [unreleased] +- add converter for api.voiapp.io/gbfs/v2 feed: remove all voi_bike entries + ## 2024-11-12 - add converter for `gbfs.prod.sharedmobility.ch/v2/gbfs/pickebike_basel` feed: set valid pricing_plan_id diff --git a/app/converters/gbfs_https_to_http.py b/app/converters/gbfs_https_to_http.py index ca75bd0..8ada07c 100644 --- a/app/converters/gbfs_https_to_http.py +++ b/app/converters/gbfs_https_to_http.py @@ -17,6 +17,7 @@ class GbfsHttpsToHttpConverter(BaseConverter): 'data.lime.bike', 'mds.bird.co', 'gbfs.prod.sharedmobility.ch', + 'api.voiapp.io', ] def convert(self, data: Union[dict, list], path: str) -> Union[dict, list]: diff --git a/app/converters/gbfs_voi_de_remove_bicycle.py b/app/converters/gbfs_voi_de_remove_bicycle.py new file mode 100644 index 0000000..de8d10d --- /dev/null +++ b/app/converters/gbfs_voi_de_remove_bicycle.py @@ -0,0 +1,49 @@ +from typing import List, Union + +from app.base_converter import BaseConverter + + +class GbfsVoiDeRemoveBicycleConverter(BaseConverter): + """ + voi_de contains no bicycles, so we can remove all voi_bike entries. + """ + + hostnames = ['api.voiapp.io'] + + def convert(self, data: Union[dict, list], path: str) -> Union[dict, list]: + if not isinstance(data, dict): + return data + + if path.endswith('/vehicle_types.json'): + fields = data.get('data', {}) + if not isinstance(fields, dict): + return data + vehicle_types = fields.get('vehicle_types', []) + if not isinstance(vehicle_types, list): + return data + newlist = [] + for vehicle_type in vehicle_types: + if vehicle_type.get('vehicle_type_id') != 'voi_bike': + newlist.append(vehicle_type) + fields['vehicle_types'] = newlist + return data + + if path.endswith('/station_status.json'): + fields = data.get('data', {}) + if not isinstance(fields, dict): + return data + stations = fields.get('stations', []) + if not isinstance(stations, list): + return data + for station in stations: + vehicle_types_available = station.get('vehicle_types_available', []) + if not isinstance(vehicle_types_available, list): + continue + newlist = [] + for vehicle_type_available in vehicle_types_available: + if vehicle_type_available.get('vehicle_type_id') != 'voi_bike': + newlist.append(vehicle_type_available) + station['vehicle_types_available'] = newlist + return data + + return data diff --git a/config_dist_dev.yaml b/config_dist_dev.yaml index d54e06f..27e042a 100644 --- a/config_dist_dev.yaml +++ b/config_dist_dev.yaml @@ -6,3 +6,4 @@ HTTP_TO_HTTPS_HOSTS: - data.lime.bike - mds.bird.co - gbfs.prod.sharedmobility.ch + - api.voiapp.io