h/plugins/twitter.py

31 lines
744 B
Python
Raw Normal View History

2009-03-15 04:14:07 +00:00
"""
twitter.py: written by Scaevolus 2009
retrieves most recent tweets
"""
import urllib
from lxml import etree
2009-03-15 04:14:07 +00:00
import hook
@hook.command
2009-03-15 04:14:07 +00:00
def twitter(bot, input):
".twitter <user> - gets most recent tweet from <user>"
2009-03-15 04:14:07 +00:00
if not input.inp.strip():
return twitter.__doc__
url = "http://twitter.com/statuses/user_timeline/%s.xml?count=1" \
% urllib.quote(input.inp)
2009-03-24 22:53:56 +00:00
try:
tweet = etree.parse(url)
except IOError:
return 'RoR: XTREME scalability (twitter gave an error)'
2009-03-15 04:14:07 +00:00
if tweet.find('error') is not None:
return "can't find that username"
2009-03-15 04:14:07 +00:00
tweet = tweet.find('status')
bot.say(': '.join(tweet.find(x).text for x in
2009-03-15 20:04:02 +00:00
'created_at user/screen_name text'.split()))