]> jfr.im git - z_archive/twitter.git/commitdiff
bandaid unicode/str.encode-related crash bug master
authorzonidjan <redacted>
Mon, 4 Apr 2016 18:00:35 +0000 (13:00 -0500)
committerzonidjan <redacted>
Mon, 4 Apr 2016 18:00:35 +0000 (13:00 -0500)
twitter/ircbot.py

index 6e9e39d8c13632ee33611aa631743e970a74ac7a..f15c2ffdb45ffedbbf1d695dec2aa89ec10e6421 100644 (file)
@@ -176,6 +176,32 @@ class TwitterBot(object):
 
         nextLastUpdate = self.lastUpdate
         for update in updates:
+            try:
+                # This part raises lots of exceptions which kill the bot
+                # (Unicode errors, etc.)
+                # Ignore any exceptions, as a band-aid.
+                crt = parsedate(update['created_at'])
+                if (crt > nextLastUpdate):
+                    text = (htmlentitydecode(
+                        update['text'].replace('\n', ' '))
+                        .encode('utf8', 'replace'))
+
+                    # Skip updates beginning with @
+                    # TODO This would be better if we only ignored messages
+                    #   to people who are not on our following list.
+                    if not text.startswith(b"@"):
+                        msg = "%s %s%s%s %s" %(
+                            get_prefix(),
+                            IRC_BOLD, update['user']['screen_name'],
+                            IRC_BOLD, text.decode('utf8'))
+                        self.privmsg_channels(msg)
+
+                    nextLastUpdate = crt
+            except Exception as e:
+                print("Exception while sending updates:", file=sys.stderr)
+                traceback.print_exc(file=sys.stderr)
+                pass # don't return as this one is likely to keep happening
+
             crt = parsedate(update['created_at'])
             if (crt > nextLastUpdate):
                 text = (htmlentitydecode(