Created
May 26, 2018 01:40
-
-
Save owenthewizard/1a643eb84d248ef622934e5ebf46fcf8 to your computer and use it in GitHub Desktop.
Fetches the top wallpaper of the given subreddit and resolution.
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
#!/usr/bin/env python3 | |
# Example: wallpaper.py wallpaper 1920x1080 | |
import json | |
import requests | |
import tempfile | |
import subprocess | |
import sys | |
subreddit = sys.argv[1] | |
resolution = sys.argv[2] | |
reddit = requests.get("http://www.reddit.com/r/{}.json".format(subreddit), headers={"user-agent":"linux:wallpaper:BETA (by /u/owenthewizard)"}) | |
for post in reddit.json()["data"]["children"]: | |
if "[{}]".format(resolution) in post["data"]["title"]: | |
url = post["data"]["url"] | |
break | |
image = requests.get(url) | |
with tempfile.NamedTemporaryFile(mode="wb") as temp: | |
temp.write(image.content) | |
subprocess.run(["feh", "--no-fehbg", "--image-bg", "black", "--bg-center", temp.name]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment