"""
# TODO add delimiter if first word isn't "is" or "was"
-# TODO handle newlines
-# TODO handle quotes
BOT_VERSION = "TwitterBot 0.2.1 (mike.verdone.ca/twitter)"
import traceback
from api import Twitter, TwitterError
+from util import htmlentitydecode
try:
import irclib
for update in updates:
crt = parse(update['created_at']).utctimetuple()
if (crt > self.lastUpdate):
- text = (
- update['text']
- .replace('\n', ' ')
- .replace(""", "\"")
- .replace('&', '&'))
+ text = (htmlentitydecode(
+ update['text'].replace('\n', ' '))
+ .encode('utf-8', 'replace'))
self.privmsg_channel(
"=^_^= %s%s%s %s" %(
IRC_BOLD, update['user']['screen_name'],
--- /dev/null
+"""
+Internal utility functions.
+
+`htmlentitydecode` came from here:
+ http://wiki.python.org/moin/EscapingHtml
+"""
+
+
+import re
+from htmlentitydefs import name2codepoint
+
+def htmlentitydecode(s):
+ return re.sub(
+ '&(%s);' % '|'.join(name2codepoint),
+ lambda m: unichr(name2codepoint[m.group(1)]), s)
+
+__all__ = ["htmlentitydecode"]