Show pictures from given subreddit

This commit is contained in:
Péter Gombos 2013-10-17 15:21:15 +02:00
parent 7d16718972
commit 304b16ee61
4 changed files with 60 additions and 65 deletions

View File

@ -1,38 +0,0 @@
#!/usr/bin/python
import os
import threading
import time
import Queue
import signal
import subprocess
import collections
q = Queue.Queue()
ls = collections.deque( ["5XTtUYV.jpg", "dwarfEntrance.png", "CD16E4u.jpg" ])
def showstuff():
while ( True ):
sb = subprocess.Popen(["feh", "-Z", "-g" ,"800x400",ls[0]])
while( True ):
a = q.get()
print a
if ( a == "stop" ):
sb.terminate()
exit()
elif ( a == "next"):
ls.rotate(1)
sb.terminate()
break
def amin():
showOff = threading.Thread(target=showstuff)
showOff.start()
for i in range(6):
time.sleep(5)
q.put("next")
time.sleep(2)
q.put("stop")
amin()

27
json_get.py Executable file
View File

@ -0,0 +1,27 @@
import json
import urllib2
def load_json(subreddit):
req = urllib2.urlopen('http://www.reddit.com/r/' + subreddit + '.json?limit=1000')
try:
json_string = json.load(req)
except ValueError:
req = urllib2.urlopen('http://www.reddit.com/r/kittens.json?limit=1000')
json_string = json.load(req)
return json_string[u'data'][u'children']
def generate_list():
obj = load_json(load_subreddit())
img_urls = []
for a in obj:
if a[u'data'][u'domain'] == u'i.imgur.com':
img_urls.append( a[u'data'][u'url'])
return img_urls
def load_subreddit():
f = open('subreddit', 'r')
subreddit = f.readline().strip()
f.close()
return subreddit

View File

@ -1,33 +1,39 @@
#!/usr/bin/python
from os import system
import json
import urllib2
import os
import threading
import time
import Queue
import signal
import subprocess
import collections
from json_get import generate_list
def load_json(subreddit):
req = urllib2.urlopen('http://www.reddit.com/r/' + subreddit + '.json?limit=1000')
try:
json_string = json.load(req)
except ValueError:
req = urllib2.urlopen('http://www.reddit.com/r/kittens.json?limit=1000')
json_string = json.load(req)
return json_string[u'data'][u'children']
q = Queue.Queue()
def add_urls_to_list(subreddit):
obj = load_json(subreddit)
img_urls = []
for a in obj:
if a[u'data'][u'domain'] == u'i.imgur.com':
img_urls.append( a[u'data'][u'url'])
return img_urls
ls = collections.deque( generate_list())
def load_subreddit():
f = open('subreddit', 'r')
subreddit = f.readline().strip()
f.close()
return subreddit
def showstuff():
while ( True ):
sb = subprocess.Popen(["feh", "-Z", "-g" ,"800x400",ls[0]])
while( True ):
a = q.get()
print a
if ( a == "stop" ):
sb.terminate()
exit()
elif ( a == "next"):
ls.rotate(1)
sb.terminate()
break
def amin():
showOff = threading.Thread(target=showstuff)
showOff.start()
for i in range(6):
time.sleep(5)
q.put("next")
time.sleep(2)
q.put("stop")
urls = add_urls_to_list(load_subreddit())
print urls
amin()

View File

@ -1 +1 @@
emmawatson
ellenpage