fix (god i hope fix) unicode in Twitter
also remove some unnecessary unicode conversions right before printing? commented out until i'm convinced there was no need for it. protip: clearest description i've read to date: http://stackoverflow.com/questions/368805/python-unicodedecodeerror-am-i-misunderstanding-encode#370199
This commit is contained in:
parent
37a677946d
commit
1bacfe047e
21
dr.botzo.py
21
dr.botzo.py
|
@ -50,9 +50,10 @@ class DrBotServerConnection(irclib.ServerConnection):
|
|||
splitpos = text.rfind(' ', 0, splitspace)
|
||||
splittext = text[0:splitpos] + ' ' + splitter
|
||||
text = splitter + ' ' + text[splitpos+1:]
|
||||
try:
|
||||
splittext = unicode(splittext).encode('utf-8')
|
||||
except UnicodeDecodeError: pass
|
||||
# unnecessary?
|
||||
#try:
|
||||
# splittext = unicode(splittext).encode('utf-8')
|
||||
#except UnicodeDecodeError: pass
|
||||
self.send_raw("PRIVMSG %s :%s" % (target, splittext))
|
||||
|
||||
times = times + 1
|
||||
|
@ -60,14 +61,16 @@ class DrBotServerConnection(irclib.ServerConnection):
|
|||
return
|
||||
|
||||
# done splitting
|
||||
try:
|
||||
text = unicode(text).encode('utf-8')
|
||||
except UnicodeDecodeError: pass
|
||||
# unnecessary?
|
||||
#try:
|
||||
# text = unicode(text).encode('utf-8')
|
||||
#except UnicodeDecodeError: pass
|
||||
self.send_raw("PRIVMSG %s :%s" % (target, text))
|
||||
else:
|
||||
try:
|
||||
text = unicode(text).encode('utf-8')
|
||||
except UnicodeDecodeError: pass
|
||||
# unnecessary?
|
||||
#try:
|
||||
# text = unicode(text).encode('utf-8')
|
||||
#except UnicodeDecodeError: pass
|
||||
self.send_raw("PRIVMSG %s :%s" % (target, text))
|
||||
|
||||
class DrBotIRC(irclib.IRC):
|
||||
|
|
|
@ -84,7 +84,7 @@ class Twitter(Module):
|
|||
if whats[1] == 'status' and len(whats) == 3:
|
||||
try:
|
||||
tweet = self.twit.GetStatus(whats[2])
|
||||
return self.reply(connection, replypath, tweet.user.name + ': ' + tweet.text)
|
||||
return self.reply(connection, replypath, tweet.user.name.encode('utf-8', 'ignore') + ': ' + tweet.text.encode('utf-8', 'ignore'))
|
||||
except twitter.TwitterError as e:
|
||||
return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e))
|
||||
elif whats[1] == 'user' and len(whats) == 3:
|
||||
|
@ -95,7 +95,7 @@ class Twitter(Module):
|
|||
tweets = self.twit.GetUserTimeline(screen_name=whats[2], count=30, include_rts=False)
|
||||
if tweets:
|
||||
tweet = tweets[0]
|
||||
return self.reply(connection, replypath, tweet.user.name + ': ' + tweet.text)
|
||||
return self.reply(connection, replypath, tweet.user.name.encode('utf-8', 'ignore') + ': ' + tweet.text.encode('utf-8', 'ignore'))
|
||||
except twitter.TwitterError as e:
|
||||
return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e))
|
||||
|
||||
|
|
Loading…
Reference in New Issue