Created
August 28, 2024 12:44
-
-
Save FL33TW00D/5215d842d36727fc837b809696fca8c4 to your computer and use it in GitHub Desktop.
Mortality countdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Countdown until I turn 30. Pair with: | |
crontab -e | |
30 07 * * * /usr/bin/python3 /home/days-till-30/countdown.py | |
""" | |
import datetime | |
from PIL import Image, ImageDraw, ImageFont | |
import os | |
import subprocess | |
def days_until_deadline(deadline): | |
today = datetime.date.today() | |
return (deadline - today).days | |
def create_image(days, width, height): | |
img = Image.new('RGB', (width, height), color='black') | |
d = ImageDraw.Draw(img) | |
subheading_font = ImageFont.truetype("/System/Library/Fonts/Supplemental/Futura.ttc", 100) | |
title_font = ImageFont.truetype("/System/Library/Fonts/Supplemental/Futura.ttc", 1000) | |
subheading_text = "DAYS UNTIL 30" | |
title_text = f"{days}" | |
bbox = d.textbbox((0, 0), title_text, font=title_font) | |
title_width = bbox[2] - bbox[0] | |
title_height = bbox[3] - bbox[1] | |
x = (width - title_width) / 2 | |
y = (height - title_height) / 2 - 200 | |
d.text((x + 250 + (title_width / 4), y + 100), subheading_text, font=subheading_font, fill=(255, 255, 255)) | |
d.text((x, y), title_text, font=title_font, fill=(255, 255, 255)) | |
return img | |
def set_desktop_wallpaper(image_path): | |
script = f''' | |
tell application "Finder" | |
set desktop picture to POSIX file "{image_path}" | |
end tell | |
''' | |
subprocess.run(["osascript", "-e", script]) | |
birthday = datetime.date(2029, 6, 29) | |
days = days_until_deadline(birthday) | |
width, height = 3024, 1964 # M3 14" | |
img = create_image(days, width, height) | |
image_path = '/Users/fleetwood/Desktop/birthday_countdown.png' | |
img.save(image_path) | |
os.system(f"defaults -currentHost write com.apple.screensaver Background -string '{image_path}'") | |
os.system("killall WallpaperAgent") | |
set_desktop_wallpaper(image_path) | |
print("Countdown image has been set as wallpaper.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment