Hack The Aesthetic!

If you're anything like me, you'll have a folder of projects that you wrote once and never looked at again. if you want to write code that you'll appreciate every day, try aesthetic! Aesthetic is a Hack Club YSWS where you to create a script that customises your Desktop Background — it could make the background reflect the weather, change with the time of day or add special text like a countdown! You'll make your digital workspace super smart AND as a reward we will ship you a lovely poster, stickers or ikea gift vouchers to decorate your physical workspace.

Ideas:

Please track your code with Hackatime and if you get stuck check the #HackTheAesthetic channel or message me directly! I'll run help sessions and am always on the other end of a DM. This YSWS is only running until Monday 28th, so get your submissions in fast!

submit here

Check out the template code below, which uses the cat API and python to get a random picture of a cat and adds a custom message based on the time of day. This could be a good starting place or useful if you find yourself stuck — but please don't submit my own code back to me with only a couple of lines changed. I'm looking for something creative or something using an API.

### Imports ###
from datetime import datetime
import PIL  # Python Imaging Library is used to read and modify the images used
import os  # Used for interacting safely with the operating system to access my secret (environmental) variable
import ctypes  # ctypes is used specifically to change the wallpaper
import requests  # Used to get cat images for the background
import urllib.request  # Used to download an image from a URL

### Constants ###
imagePath = 'C:/Users/euanr/OneDrive/Desktop/wallpaper.png'  # Replace with the DIRECT file path to your wallpaper
SPI_SETDESKWALLPAPER = 20  # Tells Windows API to perform action 20: set desktop wallpaper
APIKey = os.getenv("CatAPI")
url = 'https://api.thecatapi.com/v1/images/search'

def setWallpaper(imagePath):
    ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, os.path.abspath(imagePath).encode(), 0)

def getCurrentHour():
    current_datetime = datetime.now()
    return str(current_datetime.time())[0:2]

# Generate a message to add to the wallpaper based on the current time
hour = int(getCurrentHour())
if hour > 0 and hour < 5:
    message = "Go to sleep!!"
elif hour < 12:
    message = "have a good morning!"
elif hour < 18:
    message = "have a good afternoon!"
else:
    message = "have a good evening!"

def fetchARandomCat(APIKey, imagePath):
    headers = {
        'x-api-key': APIKey
    }
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        catPic = response.json()
        URL = catPic[0].get('url')
        urllib.request.urlretrieve(URL, imagePath)
    else:
        print(response.status_code)

fetchARandomCat(APIKey, imagePath)
setWallpaper(imagePath)

this code wont run on your computer, you need your own API key from the cat API and then you need to create an environmental variable to store it without showing everyone your secret key... here is a good tutorial :)