chiark / gitweb /
send tweets as UTF-8
authorMatthew Vernon <matthewv@chiark.greenend.org.uk>
Wed, 13 Apr 2011 10:27:27 +0000 (11:27 +0100)
committerMatthew Vernon <matthewv@chiark.greenend.org.uk>
Wed, 13 Apr 2011 10:27:27 +0000 (11:27 +0100)
Author: Colin Watson <cjwatson@chiark.greenend.org.uk>

commands.py

index 7b93d88..6049640 100644 (file)
@@ -401,19 +401,16 @@ def twitterq(bot,cmd,nick,conn,public,twitapi):
   urlstring = urlre.search(cmd).group(1)
   if (urlstring.find("twitter.com") !=-1):
     stringout = getTweet(urlstring,twitapi)
-    try:
-        bot.automsg(public, nick, stringout)
-    except UnicodeEncodeError:
-        bot.automsg(public, nick, "Sorry, that tweet contained non-ASCII characters")
+    bot.automsg(public, nick, stringout)
   
 def getTweet(urlstring,twitapi):
   parts = string.split(urlstring,'/')
   tweetID = parts[-1]
   try:
     status = twitapi.GetStatus(tweetID)
-    tweeter_screen = status.user.screen_name
-    tweeter_name = status.user.name
-    tweetText = status.text
+    tweeter_screen = status.user.screen_name.encode('UTF-8', 'replace')
+    tweeter_name = status.user.name.encode('UTF-8', 'replace')
+    tweetText = status.text.encode('UTF-8', 'replace')
     stringout = "tweet by %s (%s): %s" %(tweeter_screen,tweeter_name,tweetText)
   except twitter.TwitterError:
     terror = sys.exc_info()