I built a wallpaper switching script to help me be aware of the day outside my computer.

It uses a python package called astral to test whether the time is before or after local sunset (this changes with the seasons, of course).

Then the script automatically downloads a photo from a live webcam on top of a local TV station, sets it to be the background, and switches my local color scheme to light or dark themes as appropriate.

This runs on a cronjob, every 15 minutes, so that I have a slowly-updating view of the sun passing over the city all day.

Recently upgraded to astral v2. I want to clean up the hacky shell-script parts of it but I'll document them all below:

import datetime
from astral.sun import sun
from astral.geocoder import lookup, database
import pytz
import subprocess

tz = pytz.timezone('US/Mountain')
now = datetime.datetime.now()
now = tz.localize(now)

city = lookup("Albuquerque", database())

s = sun(city.observer, date=now)
print('Dawn:    %s' % str(s['dawn']))
print('Sunrise: %s' % str(s['sunrise']))
print('Noon:    %s' % str(s['noon']))
print('Sunset:  %s' % str(s['sunset']))
print('Dusk:    %s' % str(s['dusk']))
print('Now:     %s' % str(now))

if s['dawn'] <= now <= s['dusk']    :
    subprocess.call('/home/maze/sol/walbuquerque.sh')
else:
    subprocess.call('/home/maze/sol/dark-walbuquerque.sh')

This is the code for the shell scripts. I guess it's mostly the same, just one variable changed in the subprocess. When I was writing this in 2017 I didn't really understand how to craft a formatted string or template in python, so I just copied my shell scripts into a folder and hardwired the URL of the webcam

#! /bin/bash

curl http://wwc.instacam.com/instacamimg/KOBTV/KOBTV_l.jpg --output  ~/sol/kobtv.jpg
wal --backend colorthief --saturate 0.5 -li ~/sol/kobtv.jpg
oomoxify-cli -s /opt/spotify/Apps -f "Input Mono" ~/.cache/wal/colors-oomox
#! /bin/bash

curl http://wwc.instacam.com/instacamimg/KOBTV/KOBTV_l.jpg --output ~/sol/kobtv.jpg
wal --backend colorthief --saturate 0.5 -i ~/sol/kobtv.jpg
oomoxify-cli -s /opt/spotify/Apps -f "Input Mono" ~/.cache/wal/colors-oomox

I have some pictures of this on an old hard drive, I'll find them soon