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:
continue
else:
events.append({
evt = {
"summary": component.get("SUMMARY"),
"start": component.decoded("DTSTART"),
"end": component.decoded("DTEND"),
})
}
if "location" in component:
evt["location"] = component.decoded("LOCATION").decode()
events.append(evt)
# Sort events
events.sort(key=lambda e: e["start"])
@ -209,15 +214,21 @@ class IcalModule:
fill="black", anchor="lt", font=fnt_R
)
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:
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"],
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"])):
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"),
fill="black", anchor="lt", font=fnt_R, maxwidth=width - fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0]
)