Projects/pensieve
Projects
/
pensieve
Archived
3
0
Fork 0

Default to /r/kittens when subreddit doesn't exist

This commit is contained in:
Péter Gombos 2013-10-17 15:13:12 +02:00
parent 5c9e43aedf
commit 902288bf18
1 changed files with 6 additions and 1 deletions

View File

@ -6,7 +6,12 @@ import time
def load_json(subreddit): def load_json(subreddit):
req = urllib2.urlopen('http://www.reddit.com/r/' + subreddit + '.json?limit=1000') req = urllib2.urlopen('http://www.reddit.com/r/' + subreddit + '.json?limit=1000')
json_string = json.load(req) 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'] return json_string[u'data'][u'children']
def add_urls_to_list(subreddit): def add_urls_to_list(subreddit):