Projects/pensieve
Projects
/
pensieve
Archived
3
0
Fork 0

Add loading of img urls from subreddit name.

Use reddits json api to find image urls and add them to a list. To edit
which subreddit to find pictures from, just edit the name in the
subreddit file.
This commit is contained in:
Péter Gombos 2013-10-17 14:12:49 +02:00
parent a7c2d15637
commit 015602ce22
2 changed files with 28 additions and 0 deletions

27
pensieve.py Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/python
from os import system
import json
import urllib2
import time
def load_json(subreddit):
req = urllib2.urlopen('http://www.reddit.com/r/' + subreddit + '.json')
json_string = json.load(req)
return json_string[u'data'][u'children']
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
def load_subreddit():
f = open('subreddit', 'r')
subreddit = f.readline().strip()
f.close()
return subreddit
urls = add_urls_to_list(load_subreddit())

1
subreddit Normal file
View File

@ -0,0 +1 @@
emmawatson