Erreur de structure de données
Je modifie la structure de données au chargement pour une utilisation plus facile et rapide, il faut gérer les données brutes.
This commit is contained in:
parent
87283d36e0
commit
c80eeac919
13
vcub.py
13
vcub.py
|
@ -32,18 +32,21 @@ class Vcub ():
|
||||||
def __init__ (self, autoupdate_at_creation = None, autoupdate = False, autoupdate_delay = -1, data = None):
|
def __init__ (self, autoupdate_at_creation = None, autoupdate = False, autoupdate_delay = -1, data = None):
|
||||||
self.last_update = 0
|
self.last_update = 0
|
||||||
if type (data) == dict:
|
if type (data) == dict:
|
||||||
self.data = data
|
self.data = self.update (data = data)
|
||||||
else:
|
else:
|
||||||
self.data = None
|
self.data = None
|
||||||
if autoupdate_at_creation or (autoupdate_at_creation is None and self.data is None):
|
if autoupdate_at_creation or (autoupdate_at_creation is None and self.data is None):
|
||||||
self.update ()
|
self.update ()
|
||||||
|
|
||||||
def update (self, auto = False):
|
def update (self, auto = False, data = None):
|
||||||
'''
|
'''
|
||||||
Updates data
|
Updates data
|
||||||
auto optionnal param is to set if a update is a automatic one, and must be performed as defined in autoupdate_delay variable
|
auto optionnal param is to set if a update is a automatic one, and must be performed as defined in autoupdate_delay variable
|
||||||
'''
|
'''
|
||||||
d = get_data_from_json (vcub_url)
|
if data is None or type (data) != dict:
|
||||||
|
d = get_data_from_json (vcub_url)
|
||||||
|
else:
|
||||||
|
d = data
|
||||||
# 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 = {}
|
||||||
|
@ -112,8 +115,8 @@ class Vcub ():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
v = Vcub ()
|
v = Vcub ()
|
||||||
for i in (v.get_by_id (149), v.get_by_id (v.get_names () ['Buttiniere'])):
|
for i in (v.get_by_id (149), v.get_by_id (v.get_names () ['Buttiniere']), ):
|
||||||
print ('%s (%d) (%f, %f)%s%s\n\tbikes: %d\n\te-bikes: %d\n\tfree: %d\n\t' % (i.name, i, i.location [0], i.location [1], i.isplus and ' (VCUB+)' or '', i.online and ' ' or ' OFFLINE', i.bikes, i.ebikes, i.empty))
|
print ('%s (%d) (%f, %f)%s%s\n\tbikes: %d\n\te-bikes: %d\n\tfree: %d\n\t' % (i.name, i, i.location [0], i.location [1], i.isplus and ' (VCUB+)' or '', i.online and ' ' or ' OFFLINE', i.bikes, i.ebikes, i.empty))
|
||||||
v = Vcub (data = v.data)
|
v = Vcub (data = get_data_from_json (vcub_url))
|
||||||
for i in (v.get_by_id (v.get_locations () [(44.8875, -0.51763)]), ):
|
for i in (v.get_by_id (v.get_locations () [(44.8875, -0.51763)]), ):
|
||||||
print ('%s (%d) (%f, %f)%s%s\n\tbikes: %d\n\te-bikes: %d\n\tfree: %d\n\t' % (i.name, i, i.location [0], i.location [1], i.isplus and ' (VCUB+)' or '', i.online and ' ' or ' OFFLINE', i.bikes, i.ebikes, i.empty))
|
print ('%s (%d) (%f, %f)%s%s\n\tbikes: %d\n\te-bikes: %d\n\tfree: %d\n\t' % (i.name, i, i.location [0], i.location [1], i.isplus and ' (VCUB+)' or '', i.online and ' ' or ' OFFLINE', i.bikes, i.ebikes, i.empty))
|
Loading…
Reference in New Issue