SHARE
TWEET

Untitled

a guest Apr 19th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def all_followers(name)
  2.     client = Twitter::REST::Client.new do |config|
  3.         config.consumer_key = ""
  4.         config.consumer_secret = ""
  5.         config.access_token = ""
  6.         config.access_token_secret = ""
  7.  
  8.     end
  9.  
  10.     cursor = nil
  11.  
  12.     begin
  13.         cursor = client.followers(name, {:count <= 1000})
  14.     rescue Twitter::Error::TooManyRequests => error
  15.         puts "#{Time.current} Rate limit reached, sleaping for #{error.rate_limit.reset_in}"
  16.         sleep error.rate_limit.reset_in += 1
  17.         retry
  18.     end
  19.  
  20.     begin
  21.         cursor.each do |follower|
  22.             total_followers += 1
  23.             user = User.where(twitter_id: follower.id).first
  24.  
  25.             if user
  26.                 if user.followers <= 1000
  27.                     user.unfollow()
  28.                 else
  29.                     # do nothing
  30.                 end
  31.             end
  32.         end
  33.     rescue Twitter::Error::TooManyRequests => error
  34.         puts "#{Time.current} Rate limit reached, sleaping for #{error.rate_limit.reset_in}"
  35.         sleep error.rate_limit.reset_in += 1
  36.         retry
  37.     end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top