From 63fe328116a9c4e9d84e1e574a008e460eacc5f9 Mon Sep 17 00:00:00 2001 From: Sasha MOREL Date: Sat, 14 Aug 2021 08:50:57 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20l'acc=C3=A8s=20aux?= =?UTF-8?q?=20arr=C3=AAts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correction du style aussi. --- libs.py | 2 ++ stop.py | 22 +++++++++++++++++++++- vcub.py | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libs.py b/libs.py index ccfd90e..e823917 100644 --- a/libs.py +++ b/libs.py @@ -6,6 +6,7 @@ from json import loads as read_json from urllib import request from urllib.error import HTTPError + def get_data_from_json (url): ''' gets data from json at url @@ -16,6 +17,7 @@ def get_data_from_json (url): except HTTPError: return (None) + def hms2seconds (hhmmss): ''' Convert H:M:S string to time in seconds diff --git a/stop.py b/stop.py index fcba19e..00f6a18 100644 --- a/stop.py +++ b/stop.py @@ -4,10 +4,28 @@ Fourni les informations sur les arrêts from libs import get_data_from_json, hms2seconds 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' +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 (): ''' Récupère les informations sur un arrêt @@ -103,7 +121,9 @@ class Stop (): if __name__ == '__main__': 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]) line = s.get_line () print ('\t' + i [1]) diff --git a/vcub.py b/vcub.py index 7bea1c9..ac80b2b 100644 --- a/vcub.py +++ b/vcub.py @@ -7,6 +7,7 @@ from time import time vcub_url = 'https://ws.infotbm.com/ws/1.0/vcubs' + class Vcub (): ''' Récupère les informations des stations V³ @@ -108,5 +109,5 @@ 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']), 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)) \ No newline at end of file