Correction du style
This commit is contained in:
parent
e2456d468f
commit
bbd399004e
2
libs.py
2
libs.py
|
@ -24,5 +24,5 @@ def hms2seconds (hhmmss):
|
||||||
cut_string = hhmmss.split (':')
|
cut_string = hhmmss.split (':')
|
||||||
cut_time = (int (cut_string [0]), int (cut_string [1]), int (cut_string [2]))
|
cut_time = (int (cut_string [0]), int (cut_string [1]), int (cut_string [2]))
|
||||||
return (3600 * cut_time [0] + 60 * cut_time [1] + cut_time [2])
|
return (3600 * cut_time [0] + 60 * cut_time [1] + cut_time [2])
|
||||||
except:
|
except (IndexError, ValueError, TypeError):
|
||||||
return (0)
|
return (0)
|
30
stop.py
30
stop.py
|
@ -11,7 +11,7 @@ def get_stop_list ():
|
||||||
'''
|
'''
|
||||||
Gets stop name after its number
|
Gets stop name after its number
|
||||||
'''
|
'''
|
||||||
l = {}
|
stop_list = {}
|
||||||
|
|
||||||
# Trams
|
# Trams
|
||||||
data = get_data_from_json ('http://plandynamique.infotbm.com/api/file/trams.xml')
|
data = get_data_from_json ('http://plandynamique.infotbm.com/api/file/trams.xml')
|
||||||
|
@ -20,7 +20,7 @@ def get_stop_list ():
|
||||||
loc = None
|
loc = None
|
||||||
try:
|
try:
|
||||||
loc = (float (i ['x']), float (i ['y']))
|
loc = (float (i ['x']), float (i ['y']))
|
||||||
except:
|
except (KeyError, ValueError, TypeError):
|
||||||
pass
|
pass
|
||||||
if type (i ['ligne']) == dict:
|
if type (i ['ligne']) == dict:
|
||||||
num.append (int (i ['ligne'] ['StopPointExternalCode'].replace ('TBT', '')))
|
num.append (int (i ['ligne'] ['StopPointExternalCode'].replace ('TBT', '')))
|
||||||
|
@ -28,19 +28,19 @@ def get_stop_list ():
|
||||||
for j in i ['ligne']:
|
for j in i ['ligne']:
|
||||||
num.append (int (j ['StopPointExternalCode'].replace ('TBT', '')))
|
num.append (int (j ['StopPointExternalCode'].replace ('TBT', '')))
|
||||||
for j in num:
|
for j in num:
|
||||||
l [j] = {'name': i ['nom'], 'location': loc}
|
stop_list [j] = {'name': i ['nom'], 'location': loc}
|
||||||
#Bus
|
# Bus
|
||||||
data = get_data_from_json ('http://plandynamique.infotbm.com/api/file/bus.xml')
|
data = get_data_from_json ('http://plandynamique.infotbm.com/api/file/bus.xml')
|
||||||
for i in data ['arret']:
|
for i in data ['arret']:
|
||||||
n = int (i ['StopPointExternalCode'].replace ('TBC', ''))
|
n = int (i ['StopPointExternalCode'].replace ('TBC', ''))
|
||||||
loc = None
|
loc = None
|
||||||
try:
|
try:
|
||||||
loc = (float (i ['x']), float (i ['y']))
|
loc = (float (i ['x']), float (i ['y']))
|
||||||
except:
|
except (KeyError, ValueError, TypeError):
|
||||||
pass
|
pass
|
||||||
l [n] = {'name': i ['StopName'], 'location': loc}
|
stop_list [n] = {'name': i ['StopName'], 'location': loc}
|
||||||
|
|
||||||
return (l)
|
return (stop_list)
|
||||||
|
|
||||||
class Stop ():
|
class Stop ():
|
||||||
'''
|
'''
|
||||||
|
@ -96,11 +96,11 @@ class Stop ():
|
||||||
'''
|
'''
|
||||||
d = get_data_from_json (stop_schedule_url % self.number)
|
d = get_data_from_json (stop_schedule_url % self.number)
|
||||||
self.last_update = time ()
|
self.last_update = time ()
|
||||||
if d != False:
|
if type (d) == list:
|
||||||
self.data = []
|
self.data = []
|
||||||
# let's simplify the data
|
# let's simplify the data
|
||||||
for i in d:
|
for i in d:
|
||||||
l = {
|
line = {
|
||||||
'id': i ['code'],
|
'id': i ['code'],
|
||||||
'name': i ['name'],
|
'name': i ['name'],
|
||||||
'vehicle_type': i ['type'],
|
'vehicle_type': i ['type'],
|
||||||
|
@ -112,7 +112,7 @@ class Stop ():
|
||||||
loc = (float (j ['vehicle_lattitude']), float (j ['vehicle_longitude']))
|
loc = (float (j ['vehicle_lattitude']), float (j ['vehicle_longitude']))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
l ['vehicles'].append ({
|
line ['vehicles'].append ({
|
||||||
'id': j ['vehicle_id'],
|
'id': j ['vehicle_id'],
|
||||||
'destination': j ['destination_name'],
|
'destination': j ['destination_name'],
|
||||||
'realtime': j ['realtime'] == '1',
|
'realtime': j ['realtime'] == '1',
|
||||||
|
@ -120,7 +120,7 @@ class Stop ():
|
||||||
'wait_time': hms2seconds (j ['waittime']),
|
'wait_time': hms2seconds (j ['waittime']),
|
||||||
'arrival': int (self.last_update + hms2seconds (j ['waittime'])),
|
'arrival': int (self.last_update + hms2seconds (j ['waittime'])),
|
||||||
})
|
})
|
||||||
self.data.append (l)
|
self.data.append (line)
|
||||||
else:
|
else:
|
||||||
self.last_update = 0
|
self.last_update = 0
|
||||||
|
|
||||||
|
@ -176,10 +176,10 @@ if __name__ == '__main__':
|
||||||
print (str (i) + ' (' + stops [i] ['name'] + ') ' + str (stops [i] ['location']))
|
print (str (i) + ' (' + stops [i] ['name'] + ') ' + str (stops [i] ['location']))
|
||||||
s = Stop (i)
|
s = Stop (i)
|
||||||
for j in s.lines ():
|
for j in s.lines ():
|
||||||
l = s.get_line (j)
|
line = s.get_line (j)
|
||||||
print ('\t' + l.vehicle_type + ' ' + l.id + ' (' + l.name + ')')
|
print ('\t' + line.vehicle_type + ' ' + line.id + ' (' + line.name + ')')
|
||||||
for k in l.vehicles ():
|
for k in line.vehicles ():
|
||||||
v = l.get_vehicle (k)
|
v = line.get_vehicle (k)
|
||||||
if v.is_realtime:
|
if v.is_realtime:
|
||||||
print ('\t\t' + str (v.wait_time) + ' (' + datetime.fromtimestamp (v.arrival).strftime ('%H:%M') + ') → ' + v.destination)
|
print ('\t\t' + str (v.wait_time) + ' (' + datetime.fromtimestamp (v.arrival).strftime ('%H:%M') + ') → ' + v.destination)
|
||||||
else:
|
else:
|
||||||
|
|
7
vcub.py
7
vcub.py
|
@ -48,19 +48,19 @@ class Vcub ():
|
||||||
'''
|
'''
|
||||||
d = get_data_from_json (vcub_url)
|
d = get_data_from_json (vcub_url)
|
||||||
# the original format is awfull, so I change it a little
|
# the original format is awfull, so I change it a little
|
||||||
if d != False:
|
if type (d) == dict:
|
||||||
self.data = {}
|
self.data = {}
|
||||||
d = d ['FeatureCollection']['gml:featureMember']
|
d = d ['FeatureCollection']['gml:featureMember']
|
||||||
for i in d:
|
for i in d:
|
||||||
j = i ['bm:CI_VCUB_P']
|
j = i ['bm:CI_VCUB_P']
|
||||||
l = j ['bm:geometry'] ['gml:Point'] ['gml:pos'].split (' ')
|
loc = j ['bm:geometry'] ['gml:Point'] ['gml:pos'].split (' ')
|
||||||
e = {
|
e = {
|
||||||
'name': j ['bm:NOM'],
|
'name': j ['bm:NOM'],
|
||||||
'online': j ['bm:ETAT'] == 'CONNECTEE',
|
'online': j ['bm:ETAT'] == 'CONNECTEE',
|
||||||
'plus': j['bm:TYPE'] == 'VLS+',
|
'plus': j['bm:TYPE'] == 'VLS+',
|
||||||
'empty': int (j ['bm:NBPLACES']),
|
'empty': int (j ['bm:NBPLACES']),
|
||||||
'bikes': int (j ['bm:NBVELOS']),
|
'bikes': int (j ['bm:NBVELOS']),
|
||||||
'location': (float (l [0]), float (l [1]))
|
'location': (float (loc [0]), float (loc [1]))
|
||||||
}
|
}
|
||||||
self.data [int (j ['bm:IDENT'])] = e
|
self.data [int (j ['bm:IDENT'])] = e
|
||||||
self.last_update = time ()
|
self.last_update = time ()
|
||||||
|
@ -112,6 +112,7 @@ class Vcub ():
|
||||||
|
|
||||||
return (Station (self.data [id], id))
|
return (Station (self.data [id], id))
|
||||||
|
|
||||||
|
|
||||||
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']), 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']), v.get_by_id (v.get_locations () [(44.8875, -0.51763)])):
|
||||||
|
|
Loading…
Reference in New Issue