From dfa84076b77333ba9b9a7f81e198d64469e243a5 Mon Sep 17 00:00:00 2001 From: fram3d Date: Fri, 29 Dec 2023 20:40:22 +0100 Subject: [PATCH] add text to poster image and also write events to a text file --- .gitignore | 1 + image_poster.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index cfa07cf..a347e67 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ poster.html poster.pdf poster_light.png poster_dark.png +poster.txt http.access.log http.error.log diff --git a/image_poster.py b/image_poster.py index 56e0075..00ebf43 100755 --- a/image_poster.py +++ b/image_poster.py @@ -56,12 +56,24 @@ def drawPoster(events, bg, fg, month:int): _, _, w, _ = draw.textbbox((0, 0), subheader, font=fontIosevka) draw.text(((W-w)/2, 240), subheader, font=fontIosevka, fill=fg) - height = 410 + height = 370 draw.text((120, height), "Radionice pocinju u 19h u DC Krovu", font=fontIosevkaSmall, fill=fg) - height += 100 + height += 60 + draw.text((120, height), "Svi dogadjaji su uvek besplatni", font=fontIosevkaSmall, fill=fg) + height += 90 + + # Write list of events to sperate text file as well + textfile=open("poster.txt","w") + + textfile.write("Radionice pocinju u 19h u DC Krovu\n") + textfile.write("Svi dogadjaji su uvek besplatni\n") + + # Loop to write events both to poster image and text file for event in events: + + # Add event to image poster date = DAYS_OF_WEEK_SR[event["date"].weekday()] day = event["date"].day title = event["title"] @@ -70,6 +82,11 @@ def drawPoster(events, bg, fg, month:int): draw.text((120, height), eventText, font=fontIosevkaSmall, fill=fg) height += 70 + # Add event to textfile + textfile.write(eventText + "\n") + + textfile.close() + def drawCircle(x, y): r = 10 draw.ellipse((x - r, y - r, x + r, y+r), fill=fg, outline=(0, 0, 0), width=0)