Created
January 8, 2014 22:15
-
-
Save mubix/8325455 to your computer and use it in GitHub Desktop.
Follow All Revision 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'twitter' | |
# You can get the following by creating a "app" here: https://dev.twitter.com/apps | |
cli = Twitter::REST::Client.new do |config| | |
config.consumer_key = "" | |
config.consumer_secret = "" | |
config.access_token = "" | |
config.access_token_secret = "" | |
end | |
(0..1000).each do |x| | |
s = 10 | |
puts "Loop #{x}" | |
puts "#{Time.now.to_s} Rebalancing twitter account..." | |
begin | |
friends = cli.friend_ids.entries | |
followers = [] | |
rescue Twitter::Error | |
puts "Pulling Lists Stage - Sleeping for #{s} seconds" | |
sleep s | |
next | |
end | |
begin | |
followers = cli.follower_ids.entries | |
File.open("followers.txt", "w") do |fd| | |
fd.puts(followers.map{|x| x.to_s}.join("\n")) | |
end | |
rescue Twitter::Error::TooManyRequests | |
followers = File.readlines("followers.txt").map{|x| x.strip.to_i } | |
rescue Twitter::Error | |
puts "Mapping IDs Stage - Sleeping for #{s} seconds" | |
sleep s | |
next | |
end | |
unfollow = friends - followers | |
follow = followers - friends | |
puts "Unfollowing #{unfollow.length} people..." | |
# cli.unfollow(unfollow) | |
begin | |
puts "Following #{follow.length} people..." | |
cli.follow!(follow) | |
rescue ThreadError | |
puts "Thread Error Detected..." | |
rescue Exception => e | |
puts "Error: #{e.inspect}" | |
if e.message =~ /66885/ | |
s = 43200 # 12 hours | |
else | |
s = 10 | |
end | |
puts "Following Stage - Sleeping #{s} seconds" | |
sleep s | |
next | |
end | |
puts "Sleeping for #{s} seconds until next time" | |
sleep s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment