Compare commits
No commits in common. "62da74bf9915718f1a99b57b66c615ed7bb4371f" and "768f1c66e6165857468e52e2c6fc5882f3bfb333" have entirely different histories.
62da74bf99
...
768f1c66e6
@ -1,6 +1,5 @@
|
|||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
|
||||||
import freetype
|
import freetype
|
||||||
import io
|
import io
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
@ -9,19 +8,13 @@ import datetime as dt
|
|||||||
from dateutil import relativedelta
|
from dateutil import relativedelta
|
||||||
|
|
||||||
CURRENT_TIME = dt.date.today()
|
CURRENT_TIME = dt.date.today()
|
||||||
NEXT_MONTH = CURRENT_TIME + relativedelta.relativedelta(months=1, day=1)
|
NEXT_MONTH = CURRENT_TIME
|
||||||
DAYS_OF_WEEK_SR = ("PON", "UTO", "SRE", "ČET", "PET", "SUB", "NED")
|
DAYS_OF_WEEK_SR = ("PON", "UTO", "SRE", "ČET", "PET", "SUB", "NED")
|
||||||
MONTHS_SR = ("Januar", "Februar", "Mart", "April", "Maj", "Jun", "Jul", "Avgust",\
|
MONTHS_SR = ("Januar", "Februar", "Mart", "April", "Maj", "Jun", "Jul", "Avgust",\
|
||||||
"Septembar", "Oktobar", "Novembar", "Decembar")
|
"Septembar", "Oktobar", "Novembar", "Decembar")
|
||||||
|
|
||||||
def parseArgs(parser):
|
|
||||||
"""
|
|
||||||
Parse all arguments and return the list of argument values
|
|
||||||
"""
|
|
||||||
parser.add_argument("month", metavar = "MM", help = "two digit number representing the month for which to generate poster", default = "empty", nargs = "?")
|
|
||||||
return parser.parse_args()
|
|
||||||
|
|
||||||
def load_events(csv_path:str, month:int) -> list[dict]:
|
def load_events(csv_path:str) -> list[dict]:
|
||||||
events = []
|
events = []
|
||||||
with open(csv_path) as csv_file:
|
with open(csv_path) as csv_file:
|
||||||
csv_reader = csv.reader(csv_file)
|
csv_reader = csv.reader(csv_file)
|
||||||
@ -34,11 +27,11 @@ def load_events(csv_path:str, month:int) -> list[dict]:
|
|||||||
current_event = {"date":event_date_parsed,
|
current_event = {"date":event_date_parsed,
|
||||||
"time":event_time,
|
"time":event_time,
|
||||||
"title":event_title.strip()}
|
"title":event_title.strip()}
|
||||||
if event_date_parsed >= month:
|
if event_date_parsed >= NEXT_MONTH:
|
||||||
events.append(current_event)
|
events.append(current_event)
|
||||||
return events
|
return events
|
||||||
|
|
||||||
def drawPoster(events, bg, fg, month:int):
|
def drawPoster(events, bg, fg):
|
||||||
fontFacade = ImageFont.truetype('./site/font/Facade-Sud.woff', size=110)
|
fontFacade = ImageFont.truetype('./site/font/Facade-Sud.woff', size=110)
|
||||||
fontIosevka = ImageFont.truetype('./site/font/iosevka-regular.woff', size=60)
|
fontIosevka = ImageFont.truetype('./site/font/iosevka-regular.woff', size=60)
|
||||||
fontIosevkaSmall = ImageFont.truetype('./site/font/iosevka-regular.woff', size=45)
|
fontIosevkaSmall = ImageFont.truetype('./site/font/iosevka-regular.woff', size=45)
|
||||||
@ -52,7 +45,7 @@ def drawPoster(events, bg, fg, month:int):
|
|||||||
_, _, w, _ = draw.textbbox((0, 0), header, font=fontFacade)
|
_, _, w, _ = draw.textbbox((0, 0), header, font=fontFacade)
|
||||||
draw.text(((W-w)/2, 120), header, font=fontFacade, fill=fg)
|
draw.text(((W-w)/2, 120), header, font=fontFacade, fill=fg)
|
||||||
|
|
||||||
subheader = f"Plan za {MONTHS_SR[month.month - 1]}"
|
subheader = f"Plan za {MONTHS_SR[NEXT_MONTH.month - 1]}"
|
||||||
_, _, w, _ = draw.textbbox((0, 0), subheader, font=fontIosevka)
|
_, _, w, _ = draw.textbbox((0, 0), subheader, font=fontIosevka)
|
||||||
draw.text(((W-w)/2, 240), subheader, font=fontIosevka, fill=fg)
|
draw.text(((W-w)/2, 240), subheader, font=fontIosevka, fill=fg)
|
||||||
|
|
||||||
@ -86,26 +79,11 @@ def drawPoster(events, bg, fg, month:int):
|
|||||||
|
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def main():
|
|
||||||
# Parse arguments
|
|
||||||
parser = argparse.ArgumentParser(description="Generate images of the poster")
|
|
||||||
args = parseArgs(parser)
|
|
||||||
|
|
||||||
# Set month based on user input
|
events = load_events("dogadjaji.csv")
|
||||||
month = NEXT_MONTH
|
|
||||||
if args.month.isdigit():
|
|
||||||
month = dt.date(CURRENT_TIME.year, int(args.month), 1)
|
|
||||||
elif args.month != "empty":
|
|
||||||
print("Month has to be specified as a number. I will use next month as the default")
|
|
||||||
|
|
||||||
# Load events and draw a poseter
|
img = drawPoster(events, (0, 0, 0), (20, 250, 50))
|
||||||
events = load_events("dogadjaji.csv", month)
|
img.save('poster_dark.png')
|
||||||
|
|
||||||
img = drawPoster(events, (0, 0, 0), (20, 250, 50), month)
|
img = drawPoster(events, (255, 255, 255), (0, 0, 0))
|
||||||
img.save('poster_dark.png')
|
img.save('poster_light.png')
|
||||||
|
|
||||||
img = drawPoster(events, (255, 255, 255), (0, 0, 0), month)
|
|
||||||
img.save('poster_light.png')
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user