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])
|
||||||
|
|
Loading…
Reference in New Issue