Skip to content

Commit

Permalink
Merge pull request #762 from eskerda/fix-fifteen
Browse files Browse the repository at this point in the history
fix fifteen
  • Loading branch information
eskerda authored Oct 7, 2024
2 parents 43778f5 + 89f2585 commit d3e9584
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 48 deletions.
9 changes: 5 additions & 4 deletions pybikes/data/fifteen.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"longitude": 6.4508,
"latitude": 48.1833
},
"feed_url": "https://vilvolt.cw.fifteen.eu/api/client/stations"
"feed_url": "https://vilvolt.cw.fifteen.eu/api/client/entities"
},
{
"tag": "gijon",
Expand All @@ -31,7 +31,8 @@
"longitude": -5.6663604,
"latitude": 43.5396116
},
"feed_url": "https://bici.gijon.es/api/client/stations"
"bbox": [[43.4024, -5.8008], [43.6527, -5.4591]],
"feed_url": "https://bici.gijon.es/api/client/entities"
},
{
"tag": "auxrmlevelo",
Expand All @@ -45,7 +46,7 @@
"longitude": 3.572376,
"latitude": 47.797221
},
"feed_url": "https://auxrmlevelo.com/api/client/stations"
"feed_url": "https://auxrmlevelo.com/api/client/entities"
},
{
"tag": "velomodalis",
Expand All @@ -59,7 +60,7 @@
"longitude": -0.33,
"latitude": 45.7
},
"feed_url": "https://www.velomodalis.fr/api/client/stations"
"feed_url": "https://www.velomodalis.fr/api/client/entities"
}
]
}
55 changes: 11 additions & 44 deletions pybikes/fifteen.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
# -*- coding: utf-8 -*-

import re
import json

from pybikes import BikeShareSystem, BikeShareStation, PyBikesScraper

# Each station is formatted as:
# {
# "id": "cecqdqutu70fusn3jor0",
# "type": 2,
# "product_type": 2,
# "entity_type": 0,
# "info": {
# "bike_autonomy": 19600,
# "number_of_bikes": 10,
# "bike_state_of_charge": 69
# },
# "location": {
# "type": "Point",
# "coordinates": [
# 5.38209613,
# 43.24693037
# ]
# },
# "label": "Lapin Blanc",
# "parent_id": "ce4bhih2rcd13ifvqfr0",
# "distance": 5607.314337868474
# }
# Extracted from :https://levelo.ampmetropole.fr/api/stations at Marseille, France
from pybikes.utils import Bounded


class FifteenAPI(BikeShareSystem):
class FifteenAPI(Bounded, BikeShareSystem):

sync = True

Expand All @@ -39,8 +14,8 @@ class FifteenAPI(BikeShareSystem):
'company': ['Fifteen SAS']
}

def __init__(self, tag, feed_url, meta):
super(FifteenAPI, self).__init__(tag, meta)
def __init__(self, tag, feed_url, meta, bbox=None):
super(FifteenAPI, self).__init__(tag, meta, bounds=bbox)
self.feed_url = feed_url

def update(self, scraper=None):
Expand All @@ -56,27 +31,19 @@ def update(self, scraper=None):
else:
data = response

seen_ids = set()

for s in data:
# dedupe by parent_id
if s['parent_id'] in seen_ids:
continue
seen_ids.add(s['parent_id'])

lat = float(s['location']['coordinates'][1])
lng = float(s['location']['coordinates'][0])
lat = float(s['coordinates'][1])
lng = float(s['coordinates'][0])
name = s['label']
bikes = int(s['info']['number_of_bikes'])
bikes = int(s['availableBikes'])
slots = int(s['availableSlots'])

extra = {
'bike_state_of_charge': int(s['info'].get('bike_state_of_charge', 0)),
'bike_autonomy': int(s['info']['bike_autonomy']),
'uid': s['parent_id'],
'distance' : int(s['distance']),
'uid': s['id'],
'online': not s['isClosed'],
}

station = BikeShareStation(name, lat, lng, bikes, None, extra)
station = BikeShareStation(name, lat, lng, bikes, slots, extra)
stations.append(station)

self.stations = stations

0 comments on commit d3e9584

Please sign in to comment.