Skip to content

Instantly share code, notes, and snippets.

@sei0o
Created September 15, 2019 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sei0o/0f22d2ec7ca167112430adf22f74c0fd to your computer and use it in GitHub Desktop.
Save sei0o/0f22d2ec7ca167112430adf22f74c0fd to your computer and use it in GitHub Desktop.
Mute 'em All
require 'twitter' # $ gem install twitter
# use your app's credentials
client = Twitter::REST::Client.new do |conf|
conf.consumer_key = ""
conf.consumer_secret = ""
conf.access_token = ""
conf.access_token_secret = ""
end
# verify credentials, then confirm
screen_name = client.verify_credentials.screen_name
puts "you are logged in as @#{screen_name}. Are you sure to mute everybody you are following? (y/N)"
exit unless STDIN.gets.chomp.downcase == 'y'
# get following/muted users
following = client.friend_ids(screen_name).to_a
muted = client.muted_ids(screen_name).to_a
# mute 'em all!
ids_to_mute = following - muted
ids_to_mute.each do |id|
begin
# in my case, around 200 accounts per 15 minutes was the rate limit of mute API
# (though it was 15 accounts per 15 minutes according to docs)
result = client.mute id
rescue Twitter::Error::TooManyRequests => err
puts "Failed to mute, trying again in #{err.rate_limit.reset_in || 15 * 60} sec"
sleep (err.rate_limit.reset_in || 15 * 60) + 1
retry
end
puts "the user with id #{id} was muted."
end
puts "Finished!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment