Skip to content

Instantly share code, notes, and snippets.

@sei0o

sei0o/mute.rb

Created Sep 15, 2019
Embed
What would you like to do?
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