Created
January 11, 2021 23:53
-
-
Save remisarrailh/1b85815c6789b5f34dfc1c065c8cc89d to your computer and use it in GitHub Desktop.
Generate calendar for M5stack EPAPER
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Need Python>3.6 / Pillow / ics | |
from PIL import Image, ImageFont, ImageDraw | |
from datetime import datetime | |
from ics import Calendar | |
import requests | |
# Settings | |
font_size = 25 | |
url = "https://ateliers.labsud.org/export/categ/0.ics?from=0d" | |
filename = "image.jpg" | |
font = "font.ttf" | |
base_image = "base.jpg" # Banner sized 960x540 (will be rotate for landscape view) | |
c = Calendar(requests.get(url).text) | |
e = list(c.timeline)[:15] | |
now = datetime.now() | |
time_string = now.strftime("%d/%m/%Y %H:00") | |
# creating a image object | |
image = Image.open(base_image) | |
draw = ImageDraw.Draw(image) | |
# specified font size | |
font = ImageFont.truetype(font, font_size) | |
draw.text((770, 25), time_string, fill = "black" ,font = font, align ="left") | |
pos = 85 | |
for event in e: | |
text = "{} - {}".format(event.begin.datetime.strftime("%d/%m/%Y %H:00"), event.name) | |
print(text) | |
draw.text((30, pos), text, fill = "black" ,font = font, align ="left") | |
pos = pos + font_size + 5 | |
image = image.rotate(90, expand=1) | |
image.save(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! You may want to consider using pangocairo instead of PIL for richer (and international) text layout. See:
https://gist.github.com/dov/ae4b889acb3659ca58fba1dba103ad49