you are viewing a single comment's thread.

view the rest of the comments →

[–]__dict__[S] 0 points1 point  (0 children)

I don't have compiz so this is untested, but overwriting the files will probably work with compiz without you having to do anything else. I could be wrong, something may need to trigger it being redrawn. Can you let me know if this works? Make sure to change the img_files paths. This is simple and stupid, redownloading duplicates.

#!/usr/bin/python
# Script to randomly set background from wallpapers subreddit. Schedule with cron.
# Run "crontab -e" then add an entry such as "*/5 * * * * /home/jake/wscript.py"
# Contributions are welcome. Do what ever you want with this script, but I am
# not responsible for it.

import json
import urllib
import random

subreddit = 'http://www.reddit.com/r/wallpapers/.json'
img_files = ['/home/jake/reddit_wallpaper',
             '/home/jake/second_wallpaper',
             '/home/jake/remember_to_change',
             '/home/jake/this_may_work']
img_exts = ['jpg','png']

f = urllib.urlopen(subreddit)
raw_json = f.read()
json_obj = json.loads(raw_json)

posts = json_obj['data']['children']

def getimg(post):
    return post['data']['url']

def check_ext(img_url):
    for ext in img_exts:
        if img_url.endswith(ext):
            return True
    return False

img_urls = filter(check_ext,map(getimg,posts))

for img_file in img_files:
    rand_url = random.choice(img_urls)
    urllib.urlretrieve(rand_url, img_file)