From 304b16ee6119c4b69958257cc13c8875dec4626a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Gombos?= Date: Thu, 17 Oct 2013 15:21:15 +0200 Subject: [PATCH] Show pictures from given subreddit --- blueDart.py | 38 ----------------------------------- json_get.py | 27 +++++++++++++++++++++++++ pensieve.py | 58 +++++++++++++++++++++++++++++------------------------ subreddit | 2 +- 4 files changed, 60 insertions(+), 65 deletions(-) delete mode 100755 blueDart.py create mode 100755 json_get.py diff --git a/blueDart.py b/blueDart.py deleted file mode 100755 index cd9ca18..0000000 --- a/blueDart.py +++ /dev/null @@ -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() diff --git a/json_get.py b/json_get.py new file mode 100755 index 0000000..e934cd4 --- /dev/null +++ b/json_get.py @@ -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 + diff --git a/pensieve.py b/pensieve.py index 60a1239..88df19e 100755 --- a/pensieve.py +++ b/pensieve.py @@ -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() diff --git a/subreddit b/subreddit index 6436a8d..1cba836 100644 --- a/subreddit +++ b/subreddit @@ -1 +1 @@ -emmawatson +ellenpage