automatically select weeks to render

This commit is contained in:
Frank Adaemmer 2023-05-21 07:45:12 +02:00
parent ccbaa079d3
commit a41c8939ab

View file

@ -4,6 +4,7 @@ import json
import yaml
from PIL import Image, ImageDraw, ImageFilter
from pathlib import Path
from datetime import datetime, timedelta
def circular_mask(img):
center_x = int(img.width / 2)
@ -57,7 +58,6 @@ def create_circle(image_paths):
# Cut out a circle from each image
circular_images = [circular_mask(img) for img in shrunk_images]
circular_images[-1].save('circle.png')
if len(circular_images) == 1:
circular_images[0].save(output_path)
return
@ -82,7 +82,6 @@ def create_circle(image_paths):
def generateWeek(week, persons, locations, output_path=Path('.')):
loc = {}
for person in persons:
print(person)
if week in person['weeks'].keys():
cur_name = person['name']
cur_image = person['image']
@ -101,10 +100,7 @@ def generateWeek(week, persons, locations, output_path=Path('.')):
w,y = week.split('/')
json_file = "cw_%s_%s.json" % (w,y)
for cur_loc, cur_persons in loc.items():
print(cur_loc)
print(cur_persons)
png_file = "%s_%s_%s.png" % (cur_loc.lower(),w,y)
[print(x) for x in cur_persons]
image_paths = [("persons/%s" % x['image']) for n,x in cur_persons.items()]
img = create_circle(image_paths)
img.save(output_path / Path(png_file))
@ -121,14 +117,18 @@ def generateWeek(week, persons, locations, output_path=Path('.')):
"anchor": [x//2 for x in img.size],
"popup": popup
})
print()
with open(output_path / Path(json_file),"w") as j:
json.dump(week_json, j)
if __name__ == "__main__":
before = 4
after = 12
with open("persons.yml","r") as fp:
persons = yaml.safe_load(fp)
with open("locations.yml","r") as fp:
locations = yaml.safe_load(fp)
generateWeek('21/2023', persons, locations)
generateWeek('22/2023', persons, locations)
start = datetime.now() -timedelta(weeks=before)
for i in range(before+1+after):
cur_date = start + timedelta(weeks=i)
generateWeek(cur_date.strftime("%V/%G"), persons, locations)