Skip to content

Instantly share code, notes, and snippets.

@jl2
Created May 3, 2010 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jl2/387600 to your computer and use it in GitHub Desktop.
Save jl2/387600 to your computer and use it in GitHub Desktop.
#!/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