Skip to content

Commit 01c0243

Browse files
authored
Merge pull request #758 from eskerda/fix-le-velo
fix le velo
2 parents f7b0c43 + 8d9b943 commit 01c0243

File tree

4 files changed

+51
-30
lines changed

4 files changed

+51
-30
lines changed

pybikes/compat.py

+8
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@
4141
except ImportError:
4242
# python 2
4343
import mock
44+
45+
46+
try:
47+
from urlparse import urlparse
48+
from urlparse import parse_qs
49+
except ImportError:
50+
from urllib.parse import urlparse
51+
from urllib.parse import parse_qs

pybikes/data/fifteen.json

-16
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,6 @@
22
"system": "fifteen",
33
"class": "FifteenAPI",
44
"instances": [
5-
{
6-
"tag": "le-velo",
7-
"meta": {
8-
"city": "Marseille",
9-
"name": "LeVélo",
10-
"country": "FR",
11-
"company": [
12-
"LeVélo AMP Métropole",
13-
"Ville de Marseille",
14-
"Fifteen SAS"
15-
],
16-
"longitude": 5.36978,
17-
"latitude": 43.296482
18-
},
19-
"feed_url": "https://levelo.ampmetropole.fr/api/client/stations"
20-
},
215
{
226
"tag": "vilvolt",
237
"meta": {

pybikes/data/gbfs.json

+31-9
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,12 @@
530530
"company": [
531531
"TaM",
532532
"Fifteen"
533-
]
533+
],
534+
"source": "https://transport.data.gouv.fr/datasets/disponibilite-en-temps-reel-des-velos-en-libre-service-velomagg-de-montpellier/",
535+
"license": {
536+
"name": "Open Data Commons Open Database License (ODbL)",
537+
"url": "http://opendatacommons.org/licenses/odbl/summary/"
538+
}
534539
},
535540
"feed_url": "https://montpellier-fr.fifteen.site/gbfs/gbfs.json"
536541
},
@@ -878,8 +883,7 @@
878883
}
879884
},
880885
"feed_url": "https://gateway.prod.partners-fs37hd8.zoov.site/gbfs/2.2/landerneau/en/gbfs.json?&key=M2RjMTgyODYtZDM0OS00NjI0LWJiMjMtYzhmYjVlMDI0MzM0",
881-
"station_information": "https://gateway.prod.partners-fs37hd8.zoov.site/gbfs/2.2/landerneau/en/station_information.json?&key=M2RjMTgyODYtZDM0OS00NjI0LWJiMjMtYzhmYjVlMDI0MzM0",
882-
"station_status": "https://gateway.prod.partners-fs37hd8.zoov.site/gbfs/2.2/landerneau/en/station_status.json?&key=M2RjMTgyODYtZDM0OS00NjI0LWJiMjMtYzhmYjVlMDI0MzM0"
886+
"append_feed_args_to_req": true
883887
},
884888
{
885889
"tag": "zoov-paris-sud",
@@ -899,9 +903,7 @@
899903
}
900904
},
901905
"feed_url": "https://gateway.prod.zoov.io/gbfs/2.2/saclay/en/gbfs.json?key=NGFlMjU3MDUtNDk5My00MTM4LTk1ZjctNmNlNDM1MWQ0NjE1",
902-
"station_information": "https://gateway.prod.zoov.io/gbfs/2.2/saclay/en/station_information.json?key=NGFlMjU3MDUtNDk5My00MTM4LTk1ZjctNmNlNDM1MWQ0NjE1",
903-
"station_status": "https://gateway.prod.zoov.io/gbfs/2.2/saclay/en/station_status.json?key=NGFlMjU3MDUtNDk5My00MTM4LTk1ZjctNmNlNDM1MWQ0NjE1",
904-
"vehicle_types": "https://gateway.prod.zoov.io/gbfs/2.2/saclay/en/vehicle_types.json?key=NGFlMjU3MDUtNDk5My00MTM4LTk1ZjctNmNlNDM1MWQ0NjE1"
906+
"append_feed_args_to_req": true
905907
},
906908
{
907909
"tag": "velopartage-geneve",
@@ -1236,9 +1238,7 @@
12361238
"source": "https://www.data.gouv.fr/fr/datasets/velos-a-assistance-electrique-en-libre-service-velozef-sur-brest/"
12371239
},
12381240
"feed_url": "https://api.prod.partners-fs37hd8.zoov.eu/gbfs/2.2/brest/en/gbfs.json?&key=OGNhZDNjMDQtYTA0Yi00NzU2LWE0MTItOGJlYzE1Y2E4NGEx",
1239-
"station_information": "https://api.prod.partners-fs37hd8.zoov.eu/gbfs/2.2/brest/en/station_information.json?&key=OGNhZDNjMDQtYTA0Yi00NzU2LWE0MTItOGJlYzE1Y2E4NGEx",
1240-
"station_status": "https://api.prod.partners-fs37hd8.zoov.eu/gbfs/2.2/brest/en/station_status.json?&key=OGNhZDNjMDQtYTA0Yi00NzU2LWE0MTItOGJlYzE1Y2E4NGEx",
1241-
"vehicle_types": "https://api.prod.partners-fs37hd8.zoov.eu/gbfs/2.2/brest/en/vehicle_types.json?&key=OGNhZDNjMDQtYTA0Yi00NzU2LWE0MTItOGJlYzE1Y2E4NGEx"
1241+
"append_feed_args_to_req": true
12421242
},
12431243
{
12441244
"tag": "kotobike",
@@ -1333,6 +1333,28 @@
13331333
]
13341334
},
13351335
"feed_url": "https://gbfs.nextbike.net/maps/gbfs/v2/nextbike_eh/gbfs.json"
1336+
},
1337+
{
1338+
"tag": "le-velo",
1339+
"meta": {
1340+
"city": "Marseille",
1341+
"name": "LeVélo",
1342+
"country": "FR",
1343+
"company": [
1344+
"LeVélo AMP Métropole",
1345+
"Ville de Marseille",
1346+
"Fifteen SAS"
1347+
],
1348+
"longitude": 5.36978,
1349+
"latitude": 43.296482,
1350+
"source": "https://www.data.gouv.fr/fr/datasets/velos-a-assistance-electrique-en-libre-service-levelo-sur-marseille/",
1351+
"license": {
1352+
"name": "Open Data Commons Open Database License (ODbL)",
1353+
"url": "http://opendatacommons.org/licenses/odbl/summary/"
1354+
}
1355+
},
1356+
"append_feed_args_to_req": true,
1357+
"feed_url": "https://api.omega.fifteen.eu/gbfs/2.2/marseille/en/gbfs.json?&key=MjE0ZDNmMGEtNGFkZS00M2FlLWFmMWItZGNhOTZhMWQyYzM2"
13361358
}
13371359
],
13381360
"system": "gbfs",

pybikes/gbfs.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pybikes import BikeShareSystem, BikeShareStation, exceptions
99
from pybikes.utils import PyBikesScraper, filter_bounds
10-
from pybikes.compat import urljoin
10+
from pybikes.compat import urljoin, urlparse, parse_qs
1111

1212
try:
1313
# Python 2
@@ -33,6 +33,7 @@ def __init__(
3333
ignore_errors=False,
3434
retry=None,
3535
bbox=None,
36+
append_feed_args_to_req=False,
3637
):
3738
# Add feed_url to meta in order to be exposed to the API
3839
meta['gbfs_href'] = feed_url
@@ -43,6 +44,12 @@ def __init__(
4344
self.retry = retry
4445
self.bbox = bbox
4546

47+
if append_feed_args_to_req:
48+
purl = urlparse(feed_url)
49+
self.req_args = parse_qs(purl.query)
50+
else:
51+
self.req_args = {}
52+
4653
# Allow hardcoding feed urls on initialization
4754
self.feeds = {}
4855
if station_information:
@@ -108,7 +115,7 @@ def get_feeds(self, url, scraper, force_https):
108115
if self.feeds:
109116
return self.feeds
110117

111-
feed_data = scraper.request(url, raw=True)
118+
feed_data = scraper.request(url, params=self.req_args, raw=True)
112119

113120
# do not hide Unauthorized or Too many requests status codes
114121
if scraper.last_request.status_code in [401, 429]:
@@ -151,10 +158,10 @@ def update(self, scraper=None):
151158

152159
# Station Information and Station Status data retrieval
153160
station_information = json.loads(
154-
scraper.request(feeds['station_information'])
161+
scraper.request(feeds['station_information'], params=self.req_args)
155162
)['data']['stations']
156163
station_status = json.loads(
157-
scraper.request(feeds['station_status'])
164+
scraper.request(feeds['station_status'], params=self.req_args)
158165
)['data']['stations']
159166

160167
if 'vehicle_types' in feeds:
@@ -163,7 +170,7 @@ def update(self, scraper=None):
163170
def noop(s, v, i):
164171
warn("Unhandled vehicle type %s with count %d" % (i, v['count']))
165172

166-
vehicle_info = json.loads(scraper.request(feeds['vehicle_types']))
173+
vehicle_info = json.loads(scraper.request(feeds['vehicle_types'], params=self.req_args))
167174
# map vehicle id to vehicle info AND extra info resolver
168175
# for direct access
169176
vehicles = {

0 commit comments

Comments
 (0)