RATP: get schedule can return alerts too

This commit is contained in:
nemunaire 2023-01-16 02:28:10 +01:00
parent 20916e60d1
commit 36068e9d10
2 changed files with 42 additions and 32 deletions

View File

@ -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)
if evt_coming:
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))
occuped_space = nstops.height
alerts += nalerts
elif only_on_coming_evt:
# stop here in this case
return

View File

@ -287,6 +287,8 @@ class RATPNextStopModule:
image = Image.new('RGB', (width, height), '#fff')
draw = ImageDraw.Draw(image)
alerts = []
fnt_R = ImageFont.truetype(IDFMAPI.fnt_R_path, line_height)
fnt_B = ImageFont.truetype(IDFMAPI.fnt_RB_path, line_height)
@ -297,47 +299,54 @@ class RATPNextStopModule:
tmp = stop.split("/", 2)
mode = tmp[0][0]
line = tmp[0][1:]
if 1 < len(tmp) < 4:
prep = {}
for s in api.get_schedules(mode, line, *tmp[1:]):
if s["destination"] not in prep:
prep[s["destination"]] = []
prep[s["destination"]].append(s)
try:
if 1 < len(tmp) < 4:
prep = {}
for s in api.get_schedules(mode, line, *tmp[1:]):
if s["destination"] not in prep:
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)))
image.paste(icon, (0, align), icon)
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)
max_dest = 64
for dest, msgs in prep.items():
if len(msgs) == 0:
continue
max_dest = 64
for dest, msgs in prep.items():
if len(msgs) == 0:
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]
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(
(align_x, align),
msg["message"],
font=fnt_R, anchor="lt", fill="black"
dest,
font=fnt_B, 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)
align_x += max_dest + int(line_height/2.5)
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)))
return image
return image, alerts