automatically select weeks to render
This commit is contained in:
parent
ccbaa079d3
commit
a41c8939ab
|
|
@ -4,6 +4,7 @@ import json
|
||||||
import yaml
|
import yaml
|
||||||
from PIL import Image, ImageDraw, ImageFilter
|
from PIL import Image, ImageDraw, ImageFilter
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
def circular_mask(img):
|
def circular_mask(img):
|
||||||
center_x = int(img.width / 2)
|
center_x = int(img.width / 2)
|
||||||
|
|
@ -57,7 +58,6 @@ def create_circle(image_paths):
|
||||||
|
|
||||||
# Cut out a circle from each image
|
# Cut out a circle from each image
|
||||||
circular_images = [circular_mask(img) for img in shrunk_images]
|
circular_images = [circular_mask(img) for img in shrunk_images]
|
||||||
circular_images[-1].save('circle.png')
|
|
||||||
if len(circular_images) == 1:
|
if len(circular_images) == 1:
|
||||||
circular_images[0].save(output_path)
|
circular_images[0].save(output_path)
|
||||||
return
|
return
|
||||||
|
|
@ -82,7 +82,6 @@ def create_circle(image_paths):
|
||||||
def generateWeek(week, persons, locations, output_path=Path('.')):
|
def generateWeek(week, persons, locations, output_path=Path('.')):
|
||||||
loc = {}
|
loc = {}
|
||||||
for person in persons:
|
for person in persons:
|
||||||
print(person)
|
|
||||||
if week in person['weeks'].keys():
|
if week in person['weeks'].keys():
|
||||||
cur_name = person['name']
|
cur_name = person['name']
|
||||||
cur_image = person['image']
|
cur_image = person['image']
|
||||||
|
|
@ -101,10 +100,7 @@ def generateWeek(week, persons, locations, output_path=Path('.')):
|
||||||
w,y = week.split('/')
|
w,y = week.split('/')
|
||||||
json_file = "cw_%s_%s.json" % (w,y)
|
json_file = "cw_%s_%s.json" % (w,y)
|
||||||
for cur_loc, cur_persons in loc.items():
|
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)
|
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()]
|
image_paths = [("persons/%s" % x['image']) for n,x in cur_persons.items()]
|
||||||
img = create_circle(image_paths)
|
img = create_circle(image_paths)
|
||||||
img.save(output_path / Path(png_file))
|
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],
|
"anchor": [x//2 for x in img.size],
|
||||||
"popup": popup
|
"popup": popup
|
||||||
})
|
})
|
||||||
print()
|
|
||||||
with open(output_path / Path(json_file),"w") as j:
|
with open(output_path / Path(json_file),"w") as j:
|
||||||
json.dump(week_json, j)
|
json.dump(week_json, j)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
before = 4
|
||||||
|
after = 12
|
||||||
with open("persons.yml","r") as fp:
|
with open("persons.yml","r") as fp:
|
||||||
persons = yaml.safe_load(fp)
|
persons = yaml.safe_load(fp)
|
||||||
with open("locations.yml","r") as fp:
|
with open("locations.yml","r") as fp:
|
||||||
locations = yaml.safe_load(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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue