Skip to content

Instantly share code, notes, and snippets.

@TRSGuy
Last active January 30, 2018 12:15
Show Gist options
  • Save TRSGuy/3615540273eb131f9205ca30078514bb to your computer and use it in GitHub Desktop.
Save TRSGuy/3615540273eb131f9205ca30078514bb to your computer and use it in GitHub Desktop.
import glob, praw, requests, subprocess
from pathlib import Path
SUBREDDIT = "wallpapers"
wallpaperPath = "{}/Wallpapers/".format(str(Path.home()))
files = [i.split("/")[-1] for i in glob.glob(wallpaperPath+"*")]
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 and not post.url.split("/")[-1] in files]
req = requests.get(urls[0])
with open(wallpaperPath + urls[0].split("/")[-1], 'wb') as file:
file.write(req.content)
subprocess.call(['feh', "--bg-fill", wallpaperPath + urls[0].split("/")[-1]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment