Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A python script to randomize your Gnome desktop background using desktoppr
#!/usr/bin/env python
import os,sys
import argparse
try:
import json
except ImportError:
import simplejson as json
import urllib2
from gi.repository import Gio
parser = argparse.ArgumentParser()
parser.add_argument("-u","--user",help="Your desktoppr username")
parser.add_argument("-c","--cachedir",help="Location of the cache, defaults to ~/.config/desktoppr_cache",default="~/.config/desktoppr_cache")
args = parser.parse_args()
CACHE_DIR = os.path.expanduser(args.cachedir)
if not args.user:
sys.stderr.write("Error: no user given. Use -u.\n")
exit(1)
USER = args.user
if not os.path.isdir(CACHE_DIR):
os.makedirs(CACHE_DIR)
desktoppr_random = json.loads(urllib2.urlopen('/'.join(['https://api.desktoppr.co/1/users',USER,'wallpapers/random'])).read())
if not os.path.isfile(CACHE_DIR + str(desktoppr_random['response']['id'])):
wallpaper = open(CACHE_DIR + str(desktoppr_random['response']['id']),'w')
wallpaper.write(urllib2.urlopen(desktoppr_random['response']['image']['url']).read())
wallpaper.close();
gsetWallpaper = Gio.Settings.new('org.gnome.desktop.background')
gsetWallpaper.set_string('picture-uri',"file://" + CACHE_DIR + str(desktoppr_random['response']['id']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment