From 902288bf188ba4bdfe76f3379843f2432f2de5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Gombos?= Date: Thu, 17 Oct 2013 15:13:12 +0200 Subject: [PATCH] Default to /r/kittens when subreddit doesn't exist --- pensieve.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pensieve.py b/pensieve.py index ee7411d..60a1239 100755 --- a/pensieve.py +++ b/pensieve.py @@ -6,7 +6,12 @@ import time def load_json(subreddit): 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'] def add_urls_to_list(subreddit):