Skip to content

Instantly share code, notes, and snippets.

@cpebble
Forked from TRSGuy/get_wallpaper.py
Last active February 8, 2018 12:49
Show Gist options
  • Save cpebble/d5cd8d7763c9d42b96b75579df515ddd to your computer and use it in GitHub Desktop.
Save cpebble/d5cd8d7763c9d42b96b75579df515ddd to your computer and use it in GitHub Desktop.
import praw, subprocess
SUBREDDIT = "wallpapers"
r = praw.Reddit(client_id="",
client_secret="",
user_agent="WallpaperGrabber by /u/ParanoidBox")
allowedFormats = ['jpg', 'png']
urls = [post.url for post in r.subreddit(SUBREDDIT).hot() if post.url.split(".")[-1] in allowedFormats]
subprocess.call(['feh', "--bg-fill", urls[0])
@TRSGuy
Copy link

TRSGuy commented Jan 30, 2018

I was thinking. Wouldn't it be better if we were to limit the number of posts praw grabs using r.subreddit(SUBREDDIT).hot(limit=5)?
It has the potential of failing if we use a lower limit, because if the post doesn't contain a link to an image (if it doesn't end in .jpg, or .png), there's nothing to send to feh.
I think praw will actually forward this to the api endpoint and only ask it for five posts, so we're not just moving the "getting the first item of the list" upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment