-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchore_wheel.py
executable file
·89 lines (73 loc) · 2.82 KB
/
chore_wheel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
import argparse
import logging
import arrow
from PIL import Image, ImageDraw
import utils
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--debug", action="store_true", default=False)
parser.add_argument("-r", "--remove", action="store_true", default=False)
args = parser.parse_args()
logging.basicConfig(
format="%(asctime)s %(message)s",
level=(logging.DEBUG if args.debug else logging.INFO),
)
chore_config = utils.CHOREWHEEL
epoch = arrow.get("1970-01-01")
today = utils.NOW
def draw_chore_wheel(image_name, people, chores):
images = []
# the durations of the animation steps
durations = [60] * 3 + [100] * 2 + [125] + [175] + [6000]
drawing_people = []
for i, person_name in enumerate(people):
days = (epoch - today).days
chore = chores[(days + i) % len(chores)]
logging.debug(f"drawing {person_name} for {chore}")
drawing_people.append((person_name, chore))
if len(drawing_people) == utils.NUMBER_OF_LINES or i == len(people) - 1:
# either we've got a screen-full of chores or we've run out;
# animate this...
logging.debug(f"animating: {drawing_people}")
for n in range(8):
img = Image.new(
"RGBA", (utils.IMG_WIDTH, utils.IMG_HEIGHT), color=(24, 0, 80, 0)
)
d = ImageDraw.Draw(img)
for p, person_name in enumerate(drawing_people):
logging.debug(
f"{person_name} step: {n} y:{(32 - (n + 1) * 4)} + {(p * 8)}"
)
d.text(
xy=(1, (32 - (n + 1) * 4) + p * 8),
text=f"{person_name[0]}: {person_name[1]}",
font=utils.FONT,
fill=utils.DIVERGING_COLORS[p],
)
images.append(img)
# ... and clear the drawing buffer
drawing_people = []
images[0].save(
image_name,
save_all=True,
append_images=images[1:],
optimize=False,
duration=durations * (i + 1),
loop=2,
)
return images
def main():
chore_image = "chorewheel.gif"
chore_installation = chore_config.get("installation", "chore_wheel")
if args.remove:
logging.debug("removing")
utils.remove_installation(chore_installation)
elif chore_config.get("people") and chore_config.get("chores"):
logging.debug(f"posting chores to Tidbyt at {utils.INSTALLATION_ID}")
draw_chore_wheel(chore_image, chore_config["people"], chore_config["chores"])
utils.post_image(chore_image, chore_installation)
else:
logging.debug("no chores to post")
utils.remove_installation(chore_installation)
if __name__ == "__main__":
main()