-
-
Save cpebble/d5cd8d7763c9d42b96b75579df515ddd to your computer and use it in GitHub Desktop.
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
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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.