Instantly share code, notes, and snippets.

What would you like to do?
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
puts "Ignoring extra command line arguments!" if ARGV.size>0
# Read user's "timeline" from twitter
url = "" +
tl = Nokogiri::XML(open(url))
# Get the dates and posts
dates = tl.xpath('/statuses/status/created_at/text()').map do |x|
posts = tl.xpath('/statuses/status/text/text()').map &:to_s
# make a list of [date, post]s
pairs = 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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment