Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd78a03

Browse files
committed
Fixed up a utf8-error, thanks a lot @d1b
1 parent ca22d6f commit dd78a03

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

twitterbot.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
2-
import asyncore, random, re, twitter, urllib2
2+
# -*- coding: utf-8 -*-
3+
import asyncore, random, re, twitter, urllib2, exceptions
34
from ConfigParser import ConfigParser
45
from datetime import datetime, timedelta
56
from sys import argv, exit
@@ -63,14 +64,21 @@ def handle_msg(event, match):
6364
tweetID = tweetIDRegex.search(msg).groups()[0]
6465
try:
6566
tweet = twitterApi.GetStatus(tweetID)
66-
line = "{0} => {1}".format(tweet.user.screen_name, tweet.text)
67+
try:
68+
line = "{0} => {1}".format(tweet.user.screen_name, tweet.text)
69+
except exceptions.UnicodeEncodeError:
70+
print "Encoding error, fixing it up"
71+
tweetUni = tweet.text.encode('utf-8')
72+
print tweetUni
73+
line = "{0} => {1}".format(tweet.user.screen_name, tweetUni)
74+
6775
except twitter.TwitterError, e:
6876
if e.message == "No status found with that ID.":
6977
error = "Tweet not found"
7078
if e.message == "Sorry, you are not authorized to see this status.":
7179
error = "Tweet is private"
7280
if error:
73-
irc.action(CHANNEL,"Oshi, error!: %s" % error)
81+
irc.action(CHANNEL,"Error => %s" % error)
7482
if line:
7583
irc.action(CHANNEL, line)
7684

0 commit comments

Comments
 (0)