Mise à jour pour les V³

This commit is contained in:
Sasha MOREL 2018-07-17 23:02:25 +02:00
parent bbd399004e
commit 3675d786e4
1 changed files with 23 additions and 33 deletions

52
vcub.py
View File

@ -5,34 +5,26 @@ Provides all info about V³ stations
from libs import get_data_from_json from libs import get_data_from_json
from time import time from time import time
vcub_url = 'http://plandynamique.infotbm.com/api/vcub' vcub_url = 'https://ws.infotbm.com/ws/1.0/vcubs'
class Vcub (): class Vcub ():
''' '''
Gather stations informations Récupère les informations des stations
data format as returned by infotbm: Format de données, tel que retourné par le site infotbm :
{ {
FeatureCollection: { lists: [
gml:featureMember: [
{ {
bm:CI_VCUB_P: { 'id': numéro de la station,
bm:ETAT: str, # CONNECTEE if on, DECONNECTEE either 'name': str,
bm:TYPE: str, # VLS+ for V³+ and VLS for regular V³ station 'connexionState': 'CONNECTEE' si en service 'DECONNECTEE' sinon,
gml:boundedBy: dict, 'typeVlsPlus': 'VLS_PLUS' si + 'PAS_VLS_PLUS' sinon,
gml:id: str, 'nbPlaceAvailable': 33,
bm:NBPLACES: int, # empty spaces 'nbBikeAvailable': 0
bm:GID: int, 'latitude': float,
bm:NBVELOS: int, # available bikes 'longitude': float,
bm:HEURE: str,
bm:IDENT: int, # id as written on the station
bm:geometry: dict,
bm:NOM: str, # HR name
},
},
],
... # the rest is quite useless internal data
}, },
]
} }
''' '''
def __init__ (self, autoupdate_at_creation = True, autoupdate = False, autoupdate_delay = -1): def __init__ (self, autoupdate_at_creation = True, autoupdate = False, autoupdate_delay = -1):
@ -50,19 +42,17 @@ class Vcub ():
# the original format is awfull, so I change it a little # the original format is awfull, so I change it a little
if type (d) == dict: if type (d) == dict:
self.data = {} self.data = {}
d = d ['FeatureCollection']['gml:featureMember'] d = d ['lists']
for i in d: for i in d:
j = i ['bm:CI_VCUB_P']
loc = j ['bm:geometry'] ['gml:Point'] ['gml:pos'].split (' ')
e = { e = {
'name': j ['bm:NOM'], 'name': i ['name'],
'online': j ['bm:ETAT'] == 'CONNECTEE', 'online': i ['connexionState'] == 'CONNECTEE',
'plus': j['bm:TYPE'] == 'VLS+', 'plus': i ['typeVlsPlus'] == 'VLS_PLUS',
'empty': int (j ['bm:NBPLACES']), 'empty': int (i ['nbPlaceAvailable']),
'bikes': int (j ['bm:NBVELOS']), 'bikes': int (i ['nbBikeAvailable']),
'location': (float (loc [0]), float (loc [1])) 'location': (float (i ['latitude']), float (i ['longitude']))
} }
self.data [int (j ['bm:IDENT'])] = e self.data [int (i ['id'])] = e
self.last_update = time () self.last_update = time ()
def data_age (self): def data_age (self):