Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 17th, 2012  |  syntax: None  |  size: 1.18 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'rubygems'
  2. require 'twitter'
  3.  
  4. follower  = ARGV[0] || raise("USAGE: #$0 <follower_name> [list_name]")
  5. list_name = ARGV[1] || ("FollowedBy" + follower.upcase)
  6.  
  7. # Requires read-write token
  8. CONSUMER_KEY    = YOUR_CONFIG_HERE
  9. CONSUMER_SECRET = YOUR_CONFIG_HERE
  10. OAUTH_TOKEN     = YOUR_CONFIG_HERE
  11. OAUTH_SECRET    = YOUR_CONFIG_HERE
  12.  
  13. MAXLEN_LIST_NAME = 25
  14.  
  15. # Be gentle with Twitter API
  16. # (your mileage may vary)
  17. API_CHUNK_SIZE = 10
  18. API_LOOP_DELAY = 3
  19. MAX_RETRY      = 3
  20.  
  21. Twitter.configure do |config|
  22.   config.consumer_key       = CONSUMER_KEY
  23.   config.consumer_secret    = CONSUMER_SECRET
  24.   config.oauth_token        = OAUTH_TOKEN
  25.   config.oauth_token_secret = OAUTH_SECRET
  26. end
  27.  
  28. Twitter.list_create(list_name.slice(0,MAXLEN_LIST_NAME))
  29.  
  30. tweeps = Twitter.friend_ids(follower).collection
  31. puts "Adding #{tweeps.size} tweeps"
  32.  
  33. added = 0
  34. until tweeps.empty?
  35.   chunked_tweeps = tweeps.slice!(0,API_CHUNK_SIZE)
  36.   tries = 0
  37.   begin
  38.     tries += 1
  39.     Twitter.list_add_members(list_name,chunked_tweeps)
  40.     added += 1
  41.     print '.'
  42.     STDOUT.flush
  43.     sleep API_LOOP_DELAY
  44.   rescue
  45.     print 'x'
  46.     STDOUT.flush
  47.     sleep API_LOOP_DELAY
  48.     retry if tries < MAX_RETRY
  49.   end
  50. end
  51. puts "\nAdded #{added} tweeps"