h/plugins/twitter.py

24 lines
653 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 xml.etree import ElementTree
#command
def twitter(bot, input):
'''.twitter <user> - gets most recent tweet from <user>'''
if not input.inp.strip():
return twitter.__doc__
url = "http://twitter.com/statuses/user_timeline/%s.xml?count=1" \
% urllib.quote(input.inp)
tweet = ElementTree.parse(urllib.urlopen(url))
if tweet.find('error') is not None:
return "can't find that username"
tweet = tweet.find('status')
2009-03-15 06:51:39 +00:00
bot.say(': '.join(tweet.find(x).text for x in 'created_at user/name text'.split()))