ical: Handle location

This commit is contained in:
nemunaire 2022-08-21 04:20:22 +02:00
parent e380d544d9
commit 35be3033a8

View File

@ -86,11 +86,16 @@ class IcalModule:
elif now is not None and component.decoded("DTEND") < now: elif now is not None and component.decoded("DTEND") < now:
continue continue
else: else:
events.append({ evt = {
"summary": component.get("SUMMARY"), "summary": component.get("SUMMARY"),
"start": component.decoded("DTSTART"), "start": component.decoded("DTSTART"),
"end": component.decoded("DTEND"), "end": component.decoded("DTEND"),
}) }
if "location" in component:
evt["location"] = component.decoded("LOCATION").decode()
events.append(evt)
# Sort events # Sort events
events.sort(key=lambda e: e["start"]) events.sort(key=lambda e: e["start"])
@ -209,15 +214,21 @@ class IcalModule:
fill="black", anchor="lt", font=fnt_R fill="black", anchor="lt", font=fnt_R
) )
align += line_height * 0.7 align += line_height * 0.7
if "location" in evt and now.day == evt["start"].day:
align += display_longtext(draw,
(2 + fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
evt["location"],
fill="black", anchor="lt", font=fnt_R
)
if "info" in evt: if "info" in evt:
align += display_longtext(draw, align += display_longtext(draw,
(2 + fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.5), (2 + fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
evt["info"], evt["info"],
fill="black", anchor="lt", font=fnt_R, maxwidth=width - fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0] fill="black", anchor="lt", font=fnt_R, maxwidth=width - fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0]
) )
elif "end" in evt and (("new_start" in evt and now > evt["new_start"]) or ("new_start" not in evt and now > evt["start"])): elif "end" in evt and (("new_start" in evt and now > evt["new_start"]) or ("new_start" not in evt and now > evt["start"])):
align += display_longtext(draw, align += display_longtext(draw,
(2 + fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.5), (2 + fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
"Fin à " + (evt["new_end"] if "new_end" in evt else evt["end"]).astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M"), "Fin à " + (evt["new_end"] if "new_end" in evt else evt["end"]).astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M"),
fill="black", anchor="lt", font=fnt_R, maxwidth=width - fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0] fill="black", anchor="lt", font=fnt_R, maxwidth=width - fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0]
) )