Last active
June 28, 2019 22:28
-
-
Save ritiek/02d462ce9e649a5203d5b766cefbf4c9 to your computer and use it in GitHub Desktop.
A Python cron-job that automatically sets desktop wallpapers from my Box cloud account
This file contains 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
#!/usr/bin/python | |
import random | |
import os | |
import subprocess | |
import sys | |
from PIL import Image | |
ROOT_DIR = os.path.expanduser("~/Mount/box") | |
WALLPAPER_DIR = os.path.join(ROOT_DIR, "Pictures") | |
CHANGE_WALLPAPER_CMD = "gsettings set org.gnome.desktop.background picture-uri 'file://{}'" | |
MIN_RESOLUTION = (1920, 1080) | |
def get_random_file(directory): | |
files = os.listdir(directory) | |
chosen_file = random.choice(files) | |
return os.path.join(directory, chosen_file) | |
def set_wallpaper(wallpaper): | |
command = CHANGE_WALLPAPER_CMD.format(wallpaper) | |
return subprocess.call(command.split()) | |
if not os.path.exists(WALLPAPER_DIR): | |
sys.exit(1) | |
while True: | |
wallpaper = get_random_file(WALLPAPER_DIR) | |
img = Image.open(wallpaper) | |
width, height = img.size | |
if (width, height) >= MIN_RESOLUTION: | |
set_wallpaper(wallpaper) | |
print(wallpaper) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment