From 28a92c1a55a9304a0911024e3a09a6ab9a84785e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Fr=C3=B6hlinghaus?= Date: Fri, 6 Dec 2024 15:58:56 +0100 Subject: [PATCH 1/3] add voi_de proxy --- app/converters/gbfs_https_to_http.py | 1 + app/converters/gbfs_voi_de_remove_bicycle.py | 48 ++++++++++++++++++++ config_dist_dev.yaml | 1 + 3 files changed, 50 insertions(+) create mode 100644 app/converters/gbfs_voi_de_remove_bicycle.py 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..6eab97d --- /dev/null +++ b/app/converters/gbfs_voi_de_remove_bicycle.py @@ -0,0 +1,48 @@ +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 + newdata = [] + for vehicle_type in vehicle_types: + if vehicle_type.get('vehicle_type_id') != 'voi_bike': + newdata.append(vehicle_type) + return newdata + + 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 From 2d31924937b78a8e57a7b7418ba69e217dc36180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Fr=C3=B6hlinghaus?= Date: Fri, 6 Dec 2024 17:42:49 +0100 Subject: [PATCH 2/3] correct vehicle_types logic --- app/converters/gbfs_voi_de_remove_bicycle.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/converters/gbfs_voi_de_remove_bicycle.py b/app/converters/gbfs_voi_de_remove_bicycle.py index 6eab97d..de8d10d 100644 --- a/app/converters/gbfs_voi_de_remove_bicycle.py +++ b/app/converters/gbfs_voi_de_remove_bicycle.py @@ -21,11 +21,12 @@ def convert(self, data: Union[dict, list], path: str) -> Union[dict, list]: vehicle_types = fields.get('vehicle_types', []) if not isinstance(vehicle_types, list): return data - newdata = [] + newlist = [] for vehicle_type in vehicle_types: if vehicle_type.get('vehicle_type_id') != 'voi_bike': - newdata.append(vehicle_type) - return newdata + newlist.append(vehicle_type) + fields['vehicle_types'] = newlist + return data if path.endswith('/station_status.json'): fields = data.get('data', {}) From cbdbc72626017530d6d0e3a25be0aec35b107bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Fr=C3=B6hlinghaus?= Date: Mon, 9 Dec 2024 08:39:44 +0100 Subject: [PATCH 3/3] remove voi_bike entries --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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