V³ : ajout de l'utilisation de données déjà disponibles

This commit is contained in:
Sasha MOREL 2021-11-13 09:36:02 +01:00
parent 74fff341be
commit 87283d36e0
1 changed files with 10 additions and 4 deletions

12
vcub.py
View File

@ -29,10 +29,13 @@ class Vcub ():
]
}
'''
def __init__ (self, autoupdate_at_creation = True, autoupdate = False, autoupdate_delay = -1):
def __init__ (self, autoupdate_at_creation = None, autoupdate = False, autoupdate_delay = -1, data = None):
self.last_update = 0
if type (data) == dict:
self.data = data
else:
self.data = None
if autoupdate_at_creation:
if autoupdate_at_creation or (autoupdate_at_creation is None and self.data is None):
self.update ()
def update (self, auto = False):
@ -109,5 +112,8 @@ class Vcub ():
if __name__ == '__main__':
v = Vcub ()
for i in (v.get_by_id (149), v.get_by_id (v.get_names () ['Buttiniere']), v.get_by_id (v.get_locations () [(44.8875, -0.51763)])):
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))
v = Vcub (data = v.data)
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))