Skip to content

Commit d3e9584

Browse files
authored
Merge pull request #762 from eskerda/fix-fifteen
fix fifteen
2 parents 43778f5 + 89f2585 commit d3e9584

File tree

2 files changed

+16
-48
lines changed

2 files changed

+16
-48
lines changed

pybikes/data/fifteen.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"longitude": 6.4508,
1717
"latitude": 48.1833
1818
},
19-
"feed_url": "https://vilvolt.cw.fifteen.eu/api/client/stations"
19+
"feed_url": "https://vilvolt.cw.fifteen.eu/api/client/entities"
2020
},
2121
{
2222
"tag": "gijon",
@@ -31,7 +31,8 @@
3131
"longitude": -5.6663604,
3232
"latitude": 43.5396116
3333
},
34-
"feed_url": "https://bici.gijon.es/api/client/stations"
34+
"bbox": [[43.4024, -5.8008], [43.6527, -5.4591]],
35+
"feed_url": "https://bici.gijon.es/api/client/entities"
3536
},
3637
{
3738
"tag": "auxrmlevelo",
@@ -45,7 +46,7 @@
4546
"longitude": 3.572376,
4647
"latitude": 47.797221
4748
},
48-
"feed_url": "https://auxrmlevelo.com/api/client/stations"
49+
"feed_url": "https://auxrmlevelo.com/api/client/entities"
4950
},
5051
{
5152
"tag": "velomodalis",
@@ -59,7 +60,7 @@
5960
"longitude": -0.33,
6061
"latitude": 45.7
6162
},
62-
"feed_url": "https://www.velomodalis.fr/api/client/stations"
63+
"feed_url": "https://www.velomodalis.fr/api/client/entities"
6364
}
6465
]
6566
}

pybikes/fifteen.py

+11-44
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
11
# -*- coding: utf-8 -*-
2-
3-
import re
42
import json
53

64
from pybikes import BikeShareSystem, BikeShareStation, PyBikesScraper
7-
8-
# Each station is formatted as:
9-
# {
10-
# "id": "cecqdqutu70fusn3jor0",
11-
# "type": 2,
12-
# "product_type": 2,
13-
# "entity_type": 0,
14-
# "info": {
15-
# "bike_autonomy": 19600,
16-
# "number_of_bikes": 10,
17-
# "bike_state_of_charge": 69
18-
# },
19-
# "location": {
20-
# "type": "Point",
21-
# "coordinates": [
22-
# 5.38209613,
23-
# 43.24693037
24-
# ]
25-
# },
26-
# "label": "Lapin Blanc",
27-
# "parent_id": "ce4bhih2rcd13ifvqfr0",
28-
# "distance": 5607.314337868474
29-
# }
30-
# Extracted from :https://levelo.ampmetropole.fr/api/stations at Marseille, France
5+
from pybikes.utils import Bounded
316

327

33-
class FifteenAPI(BikeShareSystem):
8+
class FifteenAPI(Bounded, BikeShareSystem):
349

3510
sync = True
3611

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

42-
def __init__(self, tag, feed_url, meta):
43-
super(FifteenAPI, self).__init__(tag, meta)
17+
def __init__(self, tag, feed_url, meta, bbox=None):
18+
super(FifteenAPI, self).__init__(tag, meta, bounds=bbox)
4419
self.feed_url = feed_url
4520

4621
def update(self, scraper=None):
@@ -56,27 +31,19 @@ def update(self, scraper=None):
5631
else:
5732
data = response
5833

59-
seen_ids = set()
60-
6134
for s in data:
62-
# dedupe by parent_id
63-
if s['parent_id'] in seen_ids:
64-
continue
65-
seen_ids.add(s['parent_id'])
66-
67-
lat = float(s['location']['coordinates'][1])
68-
lng = float(s['location']['coordinates'][0])
35+
lat = float(s['coordinates'][1])
36+
lng = float(s['coordinates'][0])
6937
name = s['label']
70-
bikes = int(s['info']['number_of_bikes'])
38+
bikes = int(s['availableBikes'])
39+
slots = int(s['availableSlots'])
7140

7241
extra = {
73-
'bike_state_of_charge': int(s['info'].get('bike_state_of_charge', 0)),
74-
'bike_autonomy': int(s['info']['bike_autonomy']),
75-
'uid': s['parent_id'],
76-
'distance' : int(s['distance']),
42+
'uid': s['id'],
43+
'online': not s['isClosed'],
7744
}
7845

79-
station = BikeShareStation(name, lat, lng, bikes, None, extra)
46+
station = BikeShareStation(name, lat, lng, bikes, slots, extra)
8047
stations.append(station)
8148

8249
self.stations = stations

0 commit comments

Comments
 (0)