Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix le velo #758

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pybikes/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@
except ImportError:
# python 2
import mock


try:
from urlparse import urlparse
from urlparse import parse_qs
except ImportError:
from urllib.parse import urlparse
from urllib.parse import parse_qs
16 changes: 0 additions & 16 deletions pybikes/data/fifteen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
"system": "fifteen",
"class": "FifteenAPI",
"instances": [
{
"tag": "le-velo",
"meta": {
"city": "Marseille",
"name": "LeVélo",
"country": "FR",
"company": [
"LeVélo AMP Métropole",
"Ville de Marseille",
"Fifteen SAS"
],
"longitude": 5.36978,
"latitude": 43.296482
},
"feed_url": "https://levelo.ampmetropole.fr/api/client/stations"
},
{
"tag": "vilvolt",
"meta": {
Expand Down
40 changes: 31 additions & 9 deletions pybikes/data/gbfs.json
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,12 @@
"company": [
"TaM",
"Fifteen"
]
],
"source": "https://transport.data.gouv.fr/datasets/disponibilite-en-temps-reel-des-velos-en-libre-service-velomagg-de-montpellier/",
"license": {
"name": "Open Data Commons Open Database License (ODbL)",
"url": "http://opendatacommons.org/licenses/odbl/summary/"
}
},
"feed_url": "https://montpellier-fr.fifteen.site/gbfs/gbfs.json"
},
Expand Down Expand Up @@ -878,8 +883,7 @@
}
},
"feed_url": "https://gateway.prod.partners-fs37hd8.zoov.site/gbfs/2.2/landerneau/en/gbfs.json?&key=M2RjMTgyODYtZDM0OS00NjI0LWJiMjMtYzhmYjVlMDI0MzM0",
"station_information": "https://gateway.prod.partners-fs37hd8.zoov.site/gbfs/2.2/landerneau/en/station_information.json?&key=M2RjMTgyODYtZDM0OS00NjI0LWJiMjMtYzhmYjVlMDI0MzM0",
"station_status": "https://gateway.prod.partners-fs37hd8.zoov.site/gbfs/2.2/landerneau/en/station_status.json?&key=M2RjMTgyODYtZDM0OS00NjI0LWJiMjMtYzhmYjVlMDI0MzM0"
"append_feed_args_to_req": true
},
{
"tag": "zoov-paris-sud",
Expand All @@ -899,9 +903,7 @@
}
},
"feed_url": "https://gateway.prod.zoov.io/gbfs/2.2/saclay/en/gbfs.json?key=NGFlMjU3MDUtNDk5My00MTM4LTk1ZjctNmNlNDM1MWQ0NjE1",
"station_information": "https://gateway.prod.zoov.io/gbfs/2.2/saclay/en/station_information.json?key=NGFlMjU3MDUtNDk5My00MTM4LTk1ZjctNmNlNDM1MWQ0NjE1",
"station_status": "https://gateway.prod.zoov.io/gbfs/2.2/saclay/en/station_status.json?key=NGFlMjU3MDUtNDk5My00MTM4LTk1ZjctNmNlNDM1MWQ0NjE1",
"vehicle_types": "https://gateway.prod.zoov.io/gbfs/2.2/saclay/en/vehicle_types.json?key=NGFlMjU3MDUtNDk5My00MTM4LTk1ZjctNmNlNDM1MWQ0NjE1"
"append_feed_args_to_req": true
},
{
"tag": "velopartage-geneve",
Expand Down Expand Up @@ -1236,9 +1238,7 @@
"source": "https://www.data.gouv.fr/fr/datasets/velos-a-assistance-electrique-en-libre-service-velozef-sur-brest/"
},
"feed_url": "https://api.prod.partners-fs37hd8.zoov.eu/gbfs/2.2/brest/en/gbfs.json?&key=OGNhZDNjMDQtYTA0Yi00NzU2LWE0MTItOGJlYzE1Y2E4NGEx",
"station_information": "https://api.prod.partners-fs37hd8.zoov.eu/gbfs/2.2/brest/en/station_information.json?&key=OGNhZDNjMDQtYTA0Yi00NzU2LWE0MTItOGJlYzE1Y2E4NGEx",
"station_status": "https://api.prod.partners-fs37hd8.zoov.eu/gbfs/2.2/brest/en/station_status.json?&key=OGNhZDNjMDQtYTA0Yi00NzU2LWE0MTItOGJlYzE1Y2E4NGEx",
"vehicle_types": "https://api.prod.partners-fs37hd8.zoov.eu/gbfs/2.2/brest/en/vehicle_types.json?&key=OGNhZDNjMDQtYTA0Yi00NzU2LWE0MTItOGJlYzE1Y2E4NGEx"
"append_feed_args_to_req": true
},
{
"tag": "kotobike",
Expand Down Expand Up @@ -1333,6 +1333,28 @@
]
},
"feed_url": "https://gbfs.nextbike.net/maps/gbfs/v2/nextbike_eh/gbfs.json"
},
{
"tag": "le-velo",
"meta": {
"city": "Marseille",
"name": "LeVélo",
"country": "FR",
"company": [
"LeVélo AMP Métropole",
"Ville de Marseille",
"Fifteen SAS"
],
"longitude": 5.36978,
"latitude": 43.296482,
"source": "https://www.data.gouv.fr/fr/datasets/velos-a-assistance-electrique-en-libre-service-levelo-sur-marseille/",
"license": {
"name": "Open Data Commons Open Database License (ODbL)",
"url": "http://opendatacommons.org/licenses/odbl/summary/"
}
},
"append_feed_args_to_req": true,
"feed_url": "https://api.omega.fifteen.eu/gbfs/2.2/marseille/en/gbfs.json?&key=MjE0ZDNmMGEtNGFkZS00M2FlLWFmMWItZGNhOTZhMWQyYzM2"
}
],
"system": "gbfs",
Expand Down
17 changes: 12 additions & 5 deletions pybikes/gbfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pybikes import BikeShareSystem, BikeShareStation, exceptions
from pybikes.utils import PyBikesScraper, filter_bounds
from pybikes.compat import urljoin
from pybikes.compat import urljoin, urlparse, parse_qs

try:
# Python 2
Expand All @@ -33,6 +33,7 @@ def __init__(
ignore_errors=False,
retry=None,
bbox=None,
append_feed_args_to_req=False,
):
# Add feed_url to meta in order to be exposed to the API
meta['gbfs_href'] = feed_url
Expand All @@ -43,6 +44,12 @@ def __init__(
self.retry = retry
self.bbox = bbox

if append_feed_args_to_req:
purl = urlparse(feed_url)
self.req_args = parse_qs(purl.query)
else:
self.req_args = {}

# Allow hardcoding feed urls on initialization
self.feeds = {}
if station_information:
Expand Down Expand Up @@ -108,7 +115,7 @@ def get_feeds(self, url, scraper, force_https):
if self.feeds:
return self.feeds

feed_data = scraper.request(url, raw=True)
feed_data = scraper.request(url, params=self.req_args, raw=True)

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

# Station Information and Station Status data retrieval
station_information = json.loads(
scraper.request(feeds['station_information'])
scraper.request(feeds['station_information'], params=self.req_args)
)['data']['stations']
station_status = json.loads(
scraper.request(feeds['station_status'])
scraper.request(feeds['station_status'], params=self.req_args)
)['data']['stations']

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

vehicle_info = json.loads(scraper.request(feeds['vehicle_types']))
vehicle_info = json.loads(scraper.request(feeds['vehicle_types'], params=self.req_args))
# map vehicle id to vehicle info AND extra info resolver
# for direct access
vehicles = {
Expand Down
Loading