Created
May 3, 2010 00:46
-
-
Save jl2/387600 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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