Commit 72c4844f authored by Niccolo Picca's avatar Niccolo Picca
Browse files

added script file

parent 50778483
#!/usr/bin/env python2.7
import praw
import random
import urllib3.contrib.pyopenssl
### stuff to avoid ssl warnings
urllib3.contrib.pyopenssl.inject_into_urllib3()
import certifi
import urllib3
http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where())
###
from sys import argv
from subprocess import call
def download(url):
path = '/tmp/' + url.split('/')[-1]
call("wget --quiet -t 10 -P /tmp/ " + url, shell=True)
return path
def show(path):
call(DISPLAY + "feh -Z -x " + MONITOR + " -B black " + path + " -D " + str(TIME) + " --cycle-once", shell=True )
call("rm "+path , shell=True)
TIME = 3.5
args = argv[1:]
DISPLAY = "DISPLAY=:0 " # X display for running via ssh
MONITOR = "-g 1024x768+0+0" # to run on primary monitor
reddit = praw.Reddit(client_id='LETPGeDJt2waAA', client_secret="xvexl757JSF9Ln6M0ze7A78WFlw",
user_agent='linux:poul_test:v0.1') #creates instance "reddit" used later for access
try:
sub = reddit.subreddit(args[0]) #sub is the selected subreddit
except:
sub = reddit.subreddit("eyebleach") #fallback to default, if arg is not specified
posts=sub.hot(limit=50) #get 50 hot posts
pictures = []
for item in posts:
if item.url.split(".")[-1] in ["jpg","png"]: #potential pictures array made out of urls ending in png or jpg
pictures+=[item.url]
path = download(pictures[random.randint(0, len(pictures)-1)]) #chooses 1 url at random and downloads it
show(path)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment