Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'twitter'
- follower = ARGV[0] || raise("USAGE: #$0 <follower_name> [list_name]")
- list_name = ARGV[1] || ("FollowedBy" + follower.upcase)
- # Requires read-write token
- CONSUMER_KEY = YOUR_CONFIG_HERE
- CONSUMER_SECRET = YOUR_CONFIG_HERE
- OAUTH_TOKEN = YOUR_CONFIG_HERE
- OAUTH_SECRET = YOUR_CONFIG_HERE
- MAXLEN_LIST_NAME = 25
- # Be gentle with Twitter API
- # (your mileage may vary)
- API_CHUNK_SIZE = 10
- API_LOOP_DELAY = 3
- MAX_RETRY = 3
- Twitter.configure do |config|
- config.consumer_key = CONSUMER_KEY
- config.consumer_secret = CONSUMER_SECRET
- config.oauth_token = OAUTH_TOKEN
- config.oauth_token_secret = OAUTH_SECRET
- end
- Twitter.list_create(list_name.slice(0,MAXLEN_LIST_NAME))
- tweeps = Twitter.friend_ids(follower).collection
- puts "Adding #{tweeps.size} tweeps"
- added = 0
- until tweeps.empty?
- chunked_tweeps = tweeps.slice!(0,API_CHUNK_SIZE)
- tries = 0
- begin
- tries += 1
- Twitter.list_add_members(list_name,chunked_tweeps)
- added += 1
- print '.'
- STDOUT.flush
- sleep API_LOOP_DELAY
- rescue
- print 'x'
- STDOUT.flush
- sleep API_LOOP_DELAY
- retry if tries < MAX_RETRY
- end
- end
- puts "\nAdded #{added} tweeps"
Advertisement
Add Comment
Please, Sign In to add comment