|
1 | 1 | #!/usr/bin/env python |
2 | | -import asyncore, random, re, twitter, urllib2 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +import asyncore, random, re, twitter, urllib2, exceptions |
3 | 4 | from ConfigParser import ConfigParser |
4 | 5 | from datetime import datetime, timedelta |
5 | 6 | from sys import argv, exit |
@@ -63,14 +64,21 @@ def handle_msg(event, match): |
63 | 64 | tweetID = tweetIDRegex.search(msg).groups()[0] |
64 | 65 | try: |
65 | 66 | 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 | + |
67 | 75 | except twitter.TwitterError, e: |
68 | 76 | if e.message == "No status found with that ID.": |
69 | 77 | error = "Tweet not found" |
70 | 78 | if e.message == "Sorry, you are not authorized to see this status.": |
71 | 79 | error = "Tweet is private" |
72 | 80 | if error: |
73 | | - irc.action(CHANNEL,"Oshi, error!: %s" % error) |
| 81 | + irc.action(CHANNEL,"Error => %s" % error) |
74 | 82 | if line: |
75 | 83 | irc.action(CHANNEL, line) |
76 | 84 |
|
|
0 commit comments