unescape > et. al. in twitter messages
This commit is contained in:
parent
d485958f93
commit
2710d6a14a
|
@ -9,14 +9,25 @@ from lxml import etree
|
||||||
import hook
|
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
|
@hook.command
|
||||||
def twitter(bot, input):
|
def twitter(input):
|
||||||
".twitter <user> - gets most recent tweet from <user>"
|
".twitter <user> - gets most recent tweet from <user>"
|
||||||
if not input.inp.strip():
|
if not input.strip():
|
||||||
return twitter.__doc__
|
return twitter.__doc__
|
||||||
|
|
||||||
url = "http://twitter.com/statuses/user_timeline/%s.xml?count=1" \
|
url = "http://twitter.com/statuses/user_timeline/%s.xml?count=1" \
|
||||||
% urllib.quote(input.inp)
|
% urllib.quote(input)
|
||||||
try:
|
try:
|
||||||
tweet = etree.parse(url)
|
tweet = etree.parse(url)
|
||||||
except IOError:
|
except IOError:
|
||||||
|
@ -26,5 +37,5 @@ def twitter(bot, input):
|
||||||
return "can't find that username"
|
return "can't find that username"
|
||||||
|
|
||||||
tweet = tweet.find('status')
|
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()))
|
'created_at user/screen_name text'.split()))
|
||||||
|
|
Loading…
Reference in New Issue