Mise à jour de l'accès aux arrêts
Correction du style aussi.
This commit is contained in:
parent
dd627a1172
commit
63fe328116
2
libs.py
2
libs.py
|
@ -6,6 +6,7 @@ from json import loads as read_json
|
||||||
from urllib import request
|
from urllib import request
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
|
|
||||||
|
|
||||||
def get_data_from_json (url):
|
def get_data_from_json (url):
|
||||||
'''
|
'''
|
||||||
gets data from json at url
|
gets data from json at url
|
||||||
|
@ -16,6 +17,7 @@ def get_data_from_json (url):
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
return (None)
|
return (None)
|
||||||
|
|
||||||
|
|
||||||
def hms2seconds (hhmmss):
|
def hms2seconds (hhmmss):
|
||||||
'''
|
'''
|
||||||
Convert H:M:S string to time in seconds
|
Convert H:M:S string to time in seconds
|
||||||
|
|
22
stop.py
22
stop.py
|
@ -4,10 +4,28 @@ Fourni les informations sur les arrêts
|
||||||
|
|
||||||
from libs import get_data_from_json, hms2seconds
|
from libs import get_data_from_json, hms2seconds
|
||||||
from time import time
|
from time import time
|
||||||
|
from urllib.parse import quote_plus
|
||||||
|
|
||||||
|
search_stop_url = 'https://ws.infotbm.com/ws/1.0/get-schedule/%s'
|
||||||
|
stop_info_url = 'https://ws.infotbm.com/ws/1.0/network/stoparea-informations/%s'
|
||||||
stop_schedule_url = 'https://ws.infotbm.com/ws/1.0/get-realtime-pass/%d/%s'
|
stop_schedule_url = 'https://ws.infotbm.com/ws/1.0/get-realtime-pass/%d/%s'
|
||||||
|
|
||||||
|
|
||||||
|
def search_stop_name (keyword):
|
||||||
|
'''
|
||||||
|
Recherche la référence d'un nom d'arrêt
|
||||||
|
'''
|
||||||
|
d = get_data_from_json (search_stop_url % quote_plus (keyword))
|
||||||
|
r = []
|
||||||
|
for i in d:
|
||||||
|
r.append ({
|
||||||
|
'name': i ['name'],
|
||||||
|
'city': i ['city'],
|
||||||
|
'ref': i ['id'],
|
||||||
|
})
|
||||||
|
return (r)
|
||||||
|
|
||||||
|
|
||||||
class Stop ():
|
class Stop ():
|
||||||
'''
|
'''
|
||||||
Récupère les informations sur un arrêt
|
Récupère les informations sur un arrêt
|
||||||
|
@ -103,7 +121,9 @@ class Stop ():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
for i in ((3687, 'A'), (1922, '32')):
|
print (search_stop_name ('Réinson'))
|
||||||
|
print (search_stop_name ('Gravière'))
|
||||||
|
for i in ((3687, 'A'), (5459, '32')):
|
||||||
s = Stop (i [0], i [1])
|
s = Stop (i [0], i [1])
|
||||||
line = s.get_line ()
|
line = s.get_line ()
|
||||||
print ('\t' + i [1])
|
print ('\t' + i [1])
|
||||||
|
|
3
vcub.py
3
vcub.py
|
@ -7,6 +7,7 @@ from time import time
|
||||||
|
|
||||||
vcub_url = 'https://ws.infotbm.com/ws/1.0/vcubs'
|
vcub_url = 'https://ws.infotbm.com/ws/1.0/vcubs'
|
||||||
|
|
||||||
|
|
||||||
class Vcub ():
|
class Vcub ():
|
||||||
'''
|
'''
|
||||||
Récupère les informations des stations V³
|
Récupère les informations des stations V³
|
||||||
|
@ -108,5 +109,5 @@ 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']), 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)])):
|
||||||
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