From 6ff39d853553f85870f2341b6c017f66de0f57a1 Mon Sep 17 00:00:00 2001 From: David Trail Date: Mon, 19 Mar 2012 00:34:09 +0100 Subject: [PATCH] Changes to make work with python < 2.6 --- grab.py | 14 ++++---------- kill.py | 4 +++- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/grab.py b/grab.py index 5c9a063..0a14939 100755 --- a/grab.py +++ b/grab.py @@ -1,7 +1,8 @@ #!/usr/bin/env python2 import sys -import json # from json import loads, dumps +try: import json +except ImportError: import simplejson as json from urllib2 import urlopen, HTTPError from time import sleep @@ -15,15 +16,8 @@ after = '' init_url = 'http://www.reddit.com/user/{user}/comments/.json?after=%s'.format(user=user) next_url = init_url % after -try: - http = urlopen(next_url) -except HTTPError: - raise HTTPError("You seem to have given an invalid user") - -try: - reddit = json.load(http) -except ValueError: - raise ValueError("Failed to decode json.") +http = urlopen(next_url) +reddit = json.load(http) datum = [] while True: diff --git a/kill.py b/kill.py index 24a0e80..264d73a 100755 --- a/kill.py +++ b/kill.py @@ -1,6 +1,8 @@ #!/usr/bin/env python2 -import json, sys, httplib, urllib +try: import json +except ImportError: import simplejson as json +import sys, httplib, urllib from datetime import datetime, timedelta from time import sleep