Para instalar lo que necesitas, en Ubuntu solo tienes que hacer:
sudo apt-get install ruby rubygems libhpricot-ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'net/http'
$username = 'user'
$password = 'secret'
def twitter(command, opts={}, type=:get)
# Open an HTTP connection to twitter.com
twitter = Net::HTTP.start('twitter.com')
# Depending on the request type, create either
# an HTTP::Get or HTTP::Post object
case type
when :get
# Append the options to the URL
command << "?" + opts.map{|k,v| "#=#" }.join('&')
req = Net::HTTP::Get.new(command)
when :post
# Set the form data with options
req = Net::HTTP::Post.new(command)
req.set_form_data(opts)
end
# Set up the authentication and
# make the request
req.basic_auth( $username, $password )
res = twitter.request(req)
# Raise an exception unless Twitter
# returned an OK result
unless res.is_a? Net::HTTPOK
doc = Hpricot(res.body)
raise "#: #"
end
# Return the request body
return res.body
end
# Make an API query and parse the output
#'/statuses/friends_timeline.xml',
doc = Hpricot(twitter(
'/statuses/user_timeline/17058142.xml',
{}
))
# If zero statuses were returned, then
# there are no new updates
if (doc/'status').length > 0
# Get the time of the first update
#last_id = (doc/'status id').first.inner_html
# Print in reverse order so newest are
# printed at the bottom of the list
st = (doc/'status').first
#user = (st/'user name').inner_html
text = (st/'text').inner_html
# prints text not directed at somebody else
if text !~ /^[[:blank:]]*@/
puts "
"
puts "#"
puts "
"
end
end