Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement