chiark / gitweb /
handle empty status objects
authorMatthew Vernon <matthewv@chiark.greenend.org.uk>
Fri, 29 Jun 2012 09:22:01 +0000 (10:22 +0100)
committerMatthew Vernon <matthewv@chiark.greenend.org.uk>
Fri, 29 Jun 2012 09:22:01 +0000 (10:22 +0100)
commands.py

index 8c22d29..e8293ef 100755 (executable)
@@ -503,8 +503,16 @@ def getTweet(urlstring,twitapi):
   tweetID = parts[-1]
   try:
     status = twitapi.GetStatus(tweetID)
-    tweeter_screen = status.user.screen_name.encode('UTF-8', 'replace')
-    tweeter_name = status.user.name.encode('UTF-8', 'replace')
+    print status, type(status), status=={}
+    if status == {}:
+        return "twitapi.GetStatus returned nothing :-("
+    if status.user == None and status.text == None:
+        return "Empty status object returned :("
+    if status.user is not None:
+        tweeter_screen = status.user.screen_name.encode('UTF-8', 'replace')
+        tweeter_name = status.user.name.encode('UTF-8', 'replace')
+    else:
+        tweeter_screen = "[not returned]" ; tweeter_name = "[not returned]"
     tweetText = status.text.encode('UTF-8', 'replace')
     tweetText = tweetText.replace('\n',' ')
     stringout = "tweet by %s (%s): %s" %(tweeter_screen,tweeter_name,tweetText)