diff --git a/plugins/twitter.py b/plugins/twitter.py index ecc01ae..d9cb50b 100644 --- a/plugins/twitter.py +++ b/plugins/twitter.py @@ -9,14 +9,25 @@ from lxml import etree import hook +def unescape_xml(string): + # unescape the 5 chars that might be escaped in xml + + # gratuitously functional + # return reduce(lambda x, y: x.replace(*y), (string, + # zip('> < ' "e; &'.split(), '> < \' " &'.split())) + + # boring, normal + return string.replace('>', '>').replace('<', '<'). \ + replace(''', "'").replace('"e;', '"').replace('&', '&') + @hook.command -def twitter(bot, input): +def twitter(input): ".twitter - gets most recent tweet from " - if not input.inp.strip(): + if not input.strip(): return twitter.__doc__ url = "http://twitter.com/statuses/user_timeline/%s.xml?count=1" \ - % urllib.quote(input.inp) + % urllib.quote(input) try: tweet = etree.parse(url) except IOError: @@ -26,5 +37,5 @@ def twitter(bot, input): return "can't find that username" tweet = tweet.find('status') - bot.say(': '.join(tweet.find(x).text for x in + return unescape_xml(': '.join(tweet.find(x).text for x in 'created_at user/screen_name text'.split()))