· 9 years ago · Oct 28, 2016, 01:10 PM
1require "rubygems"
2require "twitter"
3require "json"
4
5# things you must configure
6TWITTER_USER = "your_username"
7
8# get these from dev.twitter.com
9# (you can reuse the keys from langoliers.rb)
10CONSUMER_KEY = "your_consumer_key"
11CONSUMER_SECRET = "your_consumer_secret"
12OAUTH_TOKEN = "your_oauth_token"
13OAUTH_TOKEN_SECRET = "your_oauth_secret"
14
15### you shouldn't have to change anything below this line ###
16
17client = Twitter::REST::Client.new do |config|
18 config.consumer_key = CONSUMER_KEY
19 config.consumer_secret = CONSUMER_SECRET
20 config.access_token = OAUTH_TOKEN
21 config.access_token_secret = OAUTH_TOKEN_SECRET
22end
23
24faves = []
25oldest_fave_id = 9000000000000000000
26got_faves = true
27
28while got_faves do
29 begin
30 new_faves = client.favorites(TWITTER_USER,{:count => 200, :max_id => oldest_fave_id})
31
32 if (new_faves.length > 0) then
33 puts "Got more faves, latest is #{new_faves.last.id}"
34 oldest_fave_id = new_faves.last.id - 1
35 faves += new_faves
36 else
37 got_faves = false
38 end
39
40 rescue Twitter::Error::TooManyRequests => e
41 puts "Hit the rate limit; pausing for #{e.rate_limit.reset_in} seconds"
42 sleep e.rate_limit.reset_in
43 retry
44
45 rescue StandardError => e
46 puts e.inspect
47 exit
48 end
49end
50
51faves.each do |fave|
52 puts "Unfavoriting a tweet..."
53 begin
54 client.unfavorite(fave.id)
55
56 rescue Twitter::Error::TooManyRequests => e
57 puts "Hit the rate limit; pausing for #{e.rate_limit.reset_in} seconds"
58 sleep e.rate_limit.reset_in
59 retry
60
61 rescue StandardError => e
62 puts e.inspect
63 end
64end