RATP: get schedule can return alerts too
This commit is contained in:
parent
20916e60d1
commit
36068e9d10
2 changed files with 42 additions and 32 deletions
3
main.py
3
main.py
|
@ -85,9 +85,10 @@ def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, **
|
||||||
evt_coming = force_coming_event or ical.non_local_event_coming(config) or ical.local_event_ending(config)
|
evt_coming = force_coming_event or ical.non_local_event_coming(config) or ical.local_event_ending(config)
|
||||||
if evt_coming:
|
if evt_coming:
|
||||||
from modules.ratp import RATPNextStopModule
|
from modules.ratp import RATPNextStopModule
|
||||||
nstops = RATPNextStopModule().draw_module(config, ["RB/cite+universitaire", "M7/porte+d'italie"], int(480/1.6), 275)
|
nstops, nalerts = RATPNextStopModule().draw_module(config, ["RB/cite+universitaire/A", "M7/porte+d'italie/A", "B125/raspail+++jaures/A"], int(480/1.6), 275)
|
||||||
image.paste(nstops, (480-int(480/1.6), 255))
|
image.paste(nstops, (480-int(480/1.6), 255))
|
||||||
occuped_space = nstops.height
|
occuped_space = nstops.height
|
||||||
|
alerts += nalerts
|
||||||
elif only_on_coming_evt:
|
elif only_on_coming_evt:
|
||||||
# stop here in this case
|
# stop here in this case
|
||||||
return
|
return
|
||||||
|
|
|
@ -287,6 +287,8 @@ class RATPNextStopModule:
|
||||||
image = Image.new('RGB', (width, height), '#fff')
|
image = Image.new('RGB', (width, height), '#fff')
|
||||||
draw = ImageDraw.Draw(image)
|
draw = ImageDraw.Draw(image)
|
||||||
|
|
||||||
|
alerts = []
|
||||||
|
|
||||||
fnt_R = ImageFont.truetype(IDFMAPI.fnt_R_path, line_height)
|
fnt_R = ImageFont.truetype(IDFMAPI.fnt_R_path, line_height)
|
||||||
fnt_B = ImageFont.truetype(IDFMAPI.fnt_RB_path, line_height)
|
fnt_B = ImageFont.truetype(IDFMAPI.fnt_RB_path, line_height)
|
||||||
|
|
||||||
|
@ -297,47 +299,54 @@ class RATPNextStopModule:
|
||||||
tmp = stop.split("/", 2)
|
tmp = stop.split("/", 2)
|
||||||
mode = tmp[0][0]
|
mode = tmp[0][0]
|
||||||
line = tmp[0][1:]
|
line = tmp[0][1:]
|
||||||
if 1 < len(tmp) < 4:
|
try:
|
||||||
prep = {}
|
if 1 < len(tmp) < 4:
|
||||||
for s in api.get_schedules(mode, line, *tmp[1:]):
|
prep = {}
|
||||||
if s["destination"] not in prep:
|
for s in api.get_schedules(mode, line, *tmp[1:]):
|
||||||
prep[s["destination"]] = []
|
if s["destination"] not in prep:
|
||||||
prep[s["destination"]].append(s)
|
prep[s["destination"]] = []
|
||||||
|
prep[s["destination"]].append(s)
|
||||||
|
|
||||||
icon = IDFMAPI.get_line_icon(mode, line, int(line_height*(1.5 if len(prep.keys()) > 1 else 1)))
|
icon = IDFMAPI.get_line_icon(mode, line, int(line_height*(1.5 if len(prep.keys()) > 1 else 1)))
|
||||||
image.paste(icon, (0, align), icon)
|
image.paste(icon, (0, align), icon)
|
||||||
|
|
||||||
max_dest = 64
|
max_dest = 64
|
||||||
for dest, msgs in prep.items():
|
for dest, msgs in prep.items():
|
||||||
if len(msgs) == 0:
|
if len(msgs) == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
align_x = line_height * 2
|
align_x = line_height * 2
|
||||||
|
|
||||||
sz = fnt_B.getsize(dest)[0]
|
|
||||||
while sz > max_dest:
|
|
||||||
dest = dest[:-1]
|
|
||||||
sz = fnt_B.getsize(dest)[0]
|
sz = fnt_B.getsize(dest)[0]
|
||||||
|
while sz > max_dest:
|
||||||
|
dest = dest[:-1]
|
||||||
|
sz = fnt_B.getsize(dest)[0]
|
||||||
|
|
||||||
draw.text(
|
|
||||||
(align_x, align),
|
|
||||||
dest,
|
|
||||||
font=fnt_B, anchor="lt", fill="black"
|
|
||||||
)
|
|
||||||
|
|
||||||
align_x += max_dest + int(line_height/2.5)
|
|
||||||
|
|
||||||
for msg in [] + msgs + msgs:
|
|
||||||
draw.text(
|
draw.text(
|
||||||
(align_x, align),
|
(align_x, align),
|
||||||
msg["message"],
|
dest,
|
||||||
font=fnt_R, anchor="lt", fill="black"
|
font=fnt_B, anchor="lt", fill="black"
|
||||||
)
|
)
|
||||||
align_x += fnt_R.getsize(msg["message"])[0] + int(line_height/2.5)
|
|
||||||
|
|
||||||
align += line_height
|
align_x += max_dest + int(line_height/2.5)
|
||||||
align += int(line_height * 0.33)
|
|
||||||
|
for msg in [] + msgs + msgs:
|
||||||
|
draw.text(
|
||||||
|
(align_x, align),
|
||||||
|
msg["message"],
|
||||||
|
font=fnt_R, anchor="lt", fill="black"
|
||||||
|
)
|
||||||
|
align_x += fnt_R.getsize(msg["message"])[0] + int(line_height/2.5)
|
||||||
|
|
||||||
|
align += line_height
|
||||||
|
align += int(line_height * 0.33)
|
||||||
|
except Exception as e:
|
||||||
|
alerts.append({
|
||||||
|
"title": "Impossible de récupérer les horaires du " + mode + line + " pour " + tmp[1],
|
||||||
|
"description": type(e).__name__ + ": " + (e.message if hasattr(e, 'message') else str(e)),
|
||||||
|
"icon": "wi-earthquake.png",
|
||||||
|
})
|
||||||
|
|
||||||
image = image.crop((0,0,width, min(align, height)))
|
image = image.crop((0,0,width, min(align, height)))
|
||||||
|
|
||||||
return image
|
return image, alerts
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue