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
|
|
|
|
|
2009-04-18 00:57:18 +00:00
|
|
|
|
2009-03-16 04:30:46 +00:00
|
|
|
@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:
|
2009-04-17 03:52:47 +00:00
|
|
|
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-04-18 00:57:18 +00:00
|
|
|
|
2009-03-15 04:14:07 +00:00
|
|
|
tweet = tweet.find('status')
|
2009-04-18 00:57:18 +00:00
|
|
|
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()))
|