|
1 |
| -""" |
2 |
| -MobiData BW Proxy |
3 |
| -Copyright (c) 2023, binary butterfly GmbH |
4 |
| -All rights reserved. |
5 |
| -""" |
6 |
| - |
7 | 1 | from typing import Union
|
8 | 2 |
|
9 | 3 | from app.base_converter import BaseConverter
|
10 | 4 |
|
11 | 5 |
|
12 | 6 | class GbfsLimeRemoveStationsConverter(BaseConverter):
|
13 |
| - hostnames = ['data.lime.bike'] |
| 7 | + hostnames = ['data.lime.bike', 'gbfs.prod.sharedmobility.ch'] |
14 | 8 |
|
15 | 9 | def convert(self, data: Union[dict, list], path: str) -> Union[dict, list]:
|
16 |
| - if not path.endswith('/gbfs.json') or not isinstance(data, dict) or not isinstance(data.get('data'), dict): |
| 10 | + if not isinstance(data, dict): |
| 11 | + return data |
| 12 | + if not path.startswith(('/api/partners/v2/gbfs/', '/v2/gbfs/lime_')): |
17 | 13 | return data
|
18 | 14 |
|
19 |
| - for language in data['data']: |
20 |
| - new_feeds = [] |
21 |
| - if not isinstance(data['data'][language].get('feeds'), list): |
22 |
| - continue |
23 |
| - |
24 |
| - for feed in data['data'][language]['feeds']: |
25 |
| - if not isinstance(feed, dict) or feed.get('name') in ['station_information', 'station_status']: |
| 15 | + if path.endswith('/gbfs.json') or '/gbfs?' in path: |
| 16 | + fields = data.get('data') |
| 17 | + if not isinstance(fields, dict): |
| 18 | + return data |
| 19 | + for language in fields: |
| 20 | + feeds = fields[language].get('feeds') |
| 21 | + if not isinstance(feeds, list): |
26 | 22 | continue
|
27 |
| - |
28 |
| - new_feeds.append(feed) |
29 |
| - |
30 |
| - data['data'][language]['feeds'] = new_feeds |
| 23 | + new_feeds = [] |
| 24 | + for feed in feeds: |
| 25 | + if not isinstance(feed, dict): |
| 26 | + continue |
| 27 | + if feed.get('name') not in ['station_information', 'station_status']: |
| 28 | + new_feeds.append(feed) |
| 29 | + fields[language]['feeds'] = new_feeds |
| 30 | + return data |
31 | 31 |
|
32 | 32 | return data
|
0 commit comments