2009-03-15 04:14:07 +00:00
|
|
|
"""
|
|
|
|
twitter.py: written by Scaevolus 2009
|
|
|
|
retrieves most recent tweets
|
|
|
|
"""
|
|
|
|
|
|
|
|
import urllib
|
2009-03-17 00:55:54 +00:00
|
|
|
from lxml import etree
|
2009-03-15 04:14:07 +00:00
|
|
|
|
2009-03-16 04:30:46 +00:00
|
|
|
import hook
|
|
|
|
|
|
|
|
@hook.command
|
2009-03-15 04:14:07 +00:00
|
|
|
def twitter(bot, input):
|
2009-03-17 00:55:54 +00:00
|
|
|
".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 is unresponsive)'
|
2009-03-15 04:14:07 +00:00
|
|
|
|
|
|
|
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()))
|