From 5ec7ac71779e9f0fde689ff6e65054bdd049ad14 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Wed, 19 Jan 2011 23:12:01 -0600 Subject: [PATCH] Twitter: unescape some xml entities that may show up in the input. this should maybe be moved into DrBotIRC or something, it'll likely be handy elsewhere. --- modules/Twitter.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/Twitter.py b/modules/Twitter.py index 8ba2be9..fe43d00 100644 --- a/modules/Twitter.py +++ b/modules/Twitter.py @@ -246,14 +246,14 @@ class Twitter(Module): if tweet.retweeted_status: retweet = tweet.retweeted_status if print_source: - return '%s (RT %s): %s [%s]' % (tweet.user.name.encode('utf-8', 'ignore'), retweet.user.name.encode('utf-8', 'ignore'), retweet.text.encode('utf-8', 'ignore'), tweet.id) + return '%s (RT %s): %s [%s]' % (tweet.user.name.encode('utf-8', 'ignore'), retweet.user.name.encode('utf-8', 'ignore'), self._unescape(retweet.text.encode('utf-8', 'ignore')), tweet.id) else: - return '(RT %s): %s [%s]' % (retweet.user.name.encode('utf-8', 'ignore'), retweet.text.encode('utf-8', 'ignore'), tweet.id) + return '(RT %s): %s [%s]' % (retweet.user.name.encode('utf-8', 'ignore'), self._unescape(retweet.text.encode('utf-8', 'ignore')), tweet.id) else: if print_source: - return '%s: %s [%s]' % (tweet.user.name.encode('utf-8', 'ignore'), tweet.text.encode('utf-8', 'ignore'), tweet.id) + return '%s: %s [%s]' % (tweet.user.name.encode('utf-8', 'ignore'), self._unescape(tweet.text.encode('utf-8', 'ignore')), tweet.id) else: - return '%s [%s]' % (tweet.text.encode('utf-8', 'ignore'), tweet.id) + return '%s [%s]' % (self._unescape(tweet.text.encode('utf-8', 'ignore')), tweet.id) def _get_last_since_id(self): """Get the since_id out of the database.""" @@ -321,5 +321,13 @@ class Twitter(Module): return latest + def _unescape(self, text): + """Convert <, >, & to their real entities.""" + + text = text.replace('<', '<') + text = text.replace('>', '>') + text = text.replace('&', '&') + return text + # vi:tabstop=4:expandtab:autoindent # kate: indent-mode python;indent-width 4;replace-tabs on;