Advertisement
Guest User

Untitled

a guest
Jun 16th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #!/usr/bin/env ruby -rubygems
  2.  
  3. abort "Usage: links.rb USERNAME [days ago]" unless ARGV.length > 0
  4. trap("SIGINT") { puts; abort }
  5.  
  6. require "twitter"
  7. require "active_support/core_ext"
  8.  
  9. username = ARGV[0]
  10. since = ARGV[1] ? ARGV[1].to_i.days.ago.to_date : 1.year.ago.to_date
  11. options = { include_entities: true, count: 200 }
  12.  
  13. loop do
  14. begin
  15. tweets = Twitter.user_timeline(username, options)
  16. rescue Twitter::Error::BadGateway, Twitter::Error::BadRequest
  17. puts "Rate Limit Exceeded (pausing for one minute)"
  18. sleep 60
  19. next
  20. end
  21.  
  22. tweets.each do |tweet|
  23. tweet_created_at = tweet.created_at.to_date
  24. abort if tweet_created_at < since
  25.  
  26. tweet.expanded_urls.compact.each do |expanded_url|
  27. puts "#{tweet_created_at}: #{expanded_url} (#{tweet.text})"
  28. end
  29. end
  30.  
  31. abort if tweets.empty?
  32. options[:max_id] = tweets.last["id"] - 1
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement