From c47d6008a0e86af6f709578b6225dd0a209ff49c Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 14 May 2009 01:38:37 -0400 Subject: [PATCH] Worked in some try/catch support for loading and hitting the API - needs to happen for other functions as well, once I have more time. --- tango.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tango.py b/tango.py index 6e97c21..cdaa788 100644 --- a/tango.py +++ b/tango.py @@ -31,11 +31,17 @@ class setup: return queryURL def getPublicTimeline(self): - publicTimeline = simplejson.load(urllib2.urlopen("http://twitter.com/statuses/public_timeline.json")) - formattedTimeline = [] - for tweet in publicTimeline: - formattedTimeline.append(tweet['text']) - return formattedTimeline + try: + publicTimeline = simplejson.load(urllib2.urlopen("http://twitter.com/statuses/public_timeline.json")) + formattedTimeline = [] + for tweet in publicTimeline: + formattedTimeline.append(tweet['text']) + return formattedTimeline + except IOError, e: + if hasattr(e, 'code'): + return "Loading API failed with HTTP Status Code " + e.code + else: + return "God help us all, Scotty, she's dead and we're not sure why." def getUserTimeline(self, **kwargs): # 99% API compliant, I think - need to figure out Gzip compression and auto-getting based on authentication