Mise en forme des horaires à l'arrêt
This commit is contained in:
89
tcl.py
89
tcl.py
@@ -10,6 +10,54 @@ import base64
|
|||||||
import difflib
|
import difflib
|
||||||
|
|
||||||
|
|
||||||
|
class Terminus:
|
||||||
|
def __init__(self, name):
|
||||||
|
self.name = name
|
||||||
|
self.horaires = []
|
||||||
|
|
||||||
|
def add_horaire(self, horaire):
|
||||||
|
self.horaires.append(horaire)
|
||||||
|
|
||||||
|
def get_horaires(self):
|
||||||
|
return self.sort_horaires()
|
||||||
|
|
||||||
|
def get_name(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def sort_horaires(self):
|
||||||
|
inth = []
|
||||||
|
for h in self.horaires:
|
||||||
|
if h == "Proche":
|
||||||
|
inth.append(0)
|
||||||
|
else :
|
||||||
|
inth.append(int(h[:-4]))
|
||||||
|
inth.sort()
|
||||||
|
return inth
|
||||||
|
|
||||||
|
class Ligne:
|
||||||
|
def __init__(self, name):
|
||||||
|
self.name = name
|
||||||
|
self.terminus = []
|
||||||
|
|
||||||
|
def add_terminus(self, newterminus):
|
||||||
|
if newterminus in self.terminus:
|
||||||
|
return
|
||||||
|
self.terminus.append(newterminus)
|
||||||
|
|
||||||
|
def get_terminus(self, term):
|
||||||
|
for t in self.terminus:
|
||||||
|
if t.get_name() == term:
|
||||||
|
return t
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_all_terminus(self):
|
||||||
|
return self.terminus
|
||||||
|
|
||||||
|
def get_name(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseProxyConfig):
|
class Config(BaseProxyConfig):
|
||||||
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
||||||
helper.copy("mail")
|
helper.copy("mail")
|
||||||
@@ -98,6 +146,7 @@ class Tcl(Plugin):
|
|||||||
url = 'https://download.data.grandlyon.com/ws/rdata/tcl_sytral.tclpassagearret/all.json?maxfeatures=2000&start=1'
|
url = 'https://download.data.grandlyon.com/ws/rdata/tcl_sytral.tclpassagearret/all.json?maxfeatures=2000&start=1'
|
||||||
respText = "<h3>Prochains départs " + nomArret + " :</h3><ul>"
|
respText = "<h3>Prochains départs " + nomArret + " :</h3><ul>"
|
||||||
self.log.info(respText)
|
self.log.info(respText)
|
||||||
|
lines = []
|
||||||
while len(url) > 0:
|
while len(url) > 0:
|
||||||
resp = await self.http.get(url, headers={'Authorization' : 'Basic ' + base64string.decode('utf-8')})
|
resp = await self.http.get(url, headers={'Authorization' : 'Basic ' + base64string.decode('utf-8')})
|
||||||
ans = await resp.text()
|
ans = await resp.text()
|
||||||
@@ -116,6 +165,7 @@ class Tcl(Plugin):
|
|||||||
for value in values:
|
for value in values:
|
||||||
if value["id"] in Ids:
|
if value["id"] in Ids:
|
||||||
if value["type"] == "E": #Filtré sur les estimés et non théoriques
|
if value["type"] == "E": #Filtré sur les estimés et non théoriques
|
||||||
|
# Les metros ont leur propre code
|
||||||
if value["coursetheorique"].split('-')[0] == "301A" :
|
if value["coursetheorique"].split('-')[0] == "301A" :
|
||||||
transport = "A"
|
transport = "A"
|
||||||
elif value["coursetheorique"].split('-')[0] == "303" :
|
elif value["coursetheorique"].split('-')[0] == "303" :
|
||||||
@@ -130,10 +180,43 @@ class Tcl(Plugin):
|
|||||||
transport = "B"
|
transport = "B"
|
||||||
else:
|
else:
|
||||||
transport = value["coursetheorique"].split('-')[0][:-1]
|
transport = value["coursetheorique"].split('-')[0][:-1]
|
||||||
respText += "<li>Ligne " + transport + " - direction " \
|
|
||||||
+ value["direction"] + " : " + value["delaipassage"] + "</li>"
|
|
||||||
self.log.info(respText)
|
|
||||||
|
|
||||||
|
found = False
|
||||||
|
for line in lines:
|
||||||
|
if line.get_name() == transport:
|
||||||
|
term = line.get_terminus(value["direction"])
|
||||||
|
if term is None:
|
||||||
|
newterm = Terminus(value["direction"])
|
||||||
|
newterm.add_horaire(value["delaipassage"])
|
||||||
|
line.add_terminus(newterm)
|
||||||
|
else:
|
||||||
|
term.add_horaire(value["delaipassage"])
|
||||||
|
found = True
|
||||||
|
if not found :
|
||||||
|
newLine = Ligne(transport)
|
||||||
|
newterm = Terminus(value["direction"])
|
||||||
|
newterm.add_horaire(value["delaipassage"])
|
||||||
|
newLine.add_terminus(newterm)
|
||||||
|
lines.append(newLine)
|
||||||
|
respText += "<ul>"
|
||||||
|
for line in lines:
|
||||||
|
self.log.info("Ligne " + line.get_name())
|
||||||
|
respText += "<li><h5>Ligne " + line.get_name() + "</h5></li>"
|
||||||
|
terms = line.get_all_terminus()
|
||||||
|
for t in terms:
|
||||||
|
self.log.info(t.get_name())
|
||||||
|
respText += "<b>Direction " + t.get_name() + "</b><ul>"
|
||||||
|
hs = t.get_horaires()
|
||||||
|
hs.sort()
|
||||||
|
for idx, h in enumerate(hs):
|
||||||
|
self.log.info(h)
|
||||||
|
if h == 0:
|
||||||
|
respText += "<li>Proche</li>"
|
||||||
|
else:
|
||||||
|
respText += "<li>" + str(h) + " min</li>"
|
||||||
|
if idx == 2: ##On limite à 3 items
|
||||||
|
break
|
||||||
|
respText += "</ul>"
|
||||||
respText += "</ul>"
|
respText += "</ul>"
|
||||||
await evt.respond(respText, allow_html=True)
|
await evt.respond(respText, allow_html=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user