Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/ruby
require 'nokogiri'
require 'open-uri'
# Handle command line
account = ARGV.shift || 'jl_2'
num = ARGV.shift || 10
if num.to_i > 200
puts "Can only fetch up to 200 tweets at a time."
num = 200
end
puts "Ignoring extra command line arguments!" if ARGV.size>0
# Read user's "timeline" from twitter
url = "http://twitter.com/statuses/user_timeline/" +
"#{account}.xml?count=#{num}"
tl = Nokogiri::XML(open(url))
# Get the dates and posts
dates = tl.xpath('/statuses/status/created_at/text()').map do |x|
Time.parse(x.to_s)
end
posts = tl.xpath('/statuses/status/text/text()').map &:to_s
# make a list of [date, post]s
pairs = dates.zip posts
# Sort by post date
pairs = pairs.sort_by &:first
# Print the tweets
pairs.each do |date,txt|
puts "%s - %s" % [date.strftime("%m/%d/%Y %I:%M %p"), txt]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment