Skip to content

Instantly share code, notes, and snippets.

@jpignata
Created December 23, 2011 19:59
Show Gist options
  • Save jpignata/1515215 to your computer and use it in GitHub Desktop.
Save jpignata/1515215 to your computer and use it in GitHub Desktop.
Frees the links hidden in your public stream
#!/usr/bin/env ruby -rubygems
abort "Usage: links.rb USERNAME [days ago]" unless ARGV.length > 0
trap("SIGINT") { puts; abort }
require "twitter"
require "active_support/core_ext"
username = ARGV[0]
since = ARGV[1] ? ARGV[1].to_i.days.ago.to_date : 1.year.ago.to_date
options = { include_entities: true, count: 200 }
loop do
begin
tweets = Twitter.user_timeline(username, options)
rescue Twitter::Error::BadGateway, Twitter::Error::BadRequest
puts "Rate Limit Exceeded (pausing for one minute)"
sleep 60
next
end
tweets.each do |tweet|
tweet_created_at = tweet.created_at.to_date
abort if tweet_created_at < since
tweet.expanded_urls.compact.each do |expanded_url|
puts "#{tweet_created_at}: #{expanded_url} (#{tweet.text})"
end
end
abort if tweets.empty?
options[:max_id] = tweets.last["id"] - 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment