1
1
# -*- coding: utf-8 -*-
2
-
3
- import re
4
2
import json
5
3
6
4
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
31
6
32
7
33
- class FifteenAPI (BikeShareSystem ):
8
+ class FifteenAPI (Bounded , BikeShareSystem ):
34
9
35
10
sync = True
36
11
@@ -39,8 +14,8 @@ class FifteenAPI(BikeShareSystem):
39
14
'company' : ['Fifteen SAS' ]
40
15
}
41
16
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 )
44
19
self .feed_url = feed_url
45
20
46
21
def update (self , scraper = None ):
@@ -56,27 +31,19 @@ def update(self, scraper=None):
56
31
else :
57
32
data = response
58
33
59
- seen_ids = set ()
60
-
61
34
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 ])
69
37
name = s ['label' ]
70
- bikes = int (s ['info' ]['number_of_bikes' ])
38
+ bikes = int (s ['availableBikes' ])
39
+ slots = int (s ['availableSlots' ])
71
40
72
41
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' ],
77
44
}
78
45
79
- station = BikeShareStation (name , lat , lng , bikes , None , extra )
46
+ station = BikeShareStation (name , lat , lng , bikes , slots , extra )
80
47
stations .append (station )
81
48
82
49
self .stations = stations
0 commit comments