Skip to content

Instantly share code, notes, and snippets.

@rileyjshaw
Forked from robinsloan/unfave.rb
Created June 13, 2017 14:59
Show Gist options
  • Save rileyjshaw/c6699c947de1a25b16614d10c2ba7aad to your computer and use it in GitHub Desktop.
Save rileyjshaw/c6699c947de1a25b16614d10c2ba7aad to your computer and use it in GitHub Desktop.
Unfave script, because why not??
#!/usr/bin/env ruby
require "rubygems"
require "twitter"
require "json"
require "faraday"
# things you must configure
TWITTER_USER = "your_username"
# get these from dev.twitter.com
# (you can reuse the keys from langoliers.rb)
CONSUMER_KEY = "your_consumer_key"
CONSUMER_SECRET = "your_consumer_secret"
OAUTH_TOKEN = "your_oauth_token"
OAUTH_TOKEN_SECRET = "your_oauth_secret"
### you shouldn't have to change anything below this line ###
client = Twitter::REST::Client.new do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.access_token = OAUTH_TOKEN
config.access_token_secret = OAUTH_TOKEN_SECRET
end
faves = []
oldest_fave_id = 9000000000000000000
got_faves = true
puts ""
puts "First we collect your faves ✨"
while got_faves do
begin
new_faves = client.favorites(TWITTER_USER,{:count => 200, :max_id => oldest_fave_id})
if (new_faves.length > 0) then
oldest_fave_id = new_faves.last.id - 1 # the - 1 is important, because of course it is
faves += new_faves
puts "Got more faves, including tweet #{new_faves.last.id}..."
else
puts "No more faves to get!"
got_faves = false
end
rescue Twitter::Error::TooManyRequests => e
puts "Hit the rate limit. Pausing for #{e.rate_limit.reset_in} seconds..."
sleep e.rate_limit.reset_in
retry
rescue StandardError => e
puts e.inspect
exit
end
end
puts ""
puts "The great unfaving begins 🙅"
faves.each do |fave|
puts "Unfavoriting tweet #{fave.id}..."
begin
client.unfavorite(fave.id)
rescue Twitter::Error::TooManyRequests => e
puts "Hit the rate limit. Pausing for #{e.rate_limit.reset_in} seconds..."
sleep e.rate_limit.reset_in
retry
rescue StandardError => e
puts e.inspect
exit
end
end
puts ""
puts "Done! 🙌"
puts ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment