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
|
|
|
|
|
2009-03-16 04:30:46 +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>'''
|
|
|
|
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 20:04:02 +00:00
|
|
|
bot.say(': '.join(tweet.find(x).text for x in
|
|
|
|
'created_at user/screen_name text'.split()))
|