Sha256: 3504c46ab4118c5d282d1508722e413107024fba71a608e419c94832bae2a198

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module DeleteMyTweets
  require 'twitter'
  require 'delete_my_tweets/version'

  class << self
    def twitter_delete(t)
      client = Twitter::REST::Client.new do |config|
        config.consumer_key        = t[CONSUMER_KEY]
        config.consumer_secret     = t[CONSUMER_SECRET]
        config.access_token        = t[ACCESS_TOKEN]
        config.access_token_secret = t[ACCESS_TOKEN_SECRET]
      end

      options = {count: 200, include_rts: true}
      user = client.user.screen_name

      begin
        exclude = t['filter']['exclude']
      rescue
        exclude = []
      end
      puts "excluding: #{exclude}" if block_given? && exclude.count>0

      begin
        tweets = client.user_timeline(user, options)
        puts "found #{tweets.count} tweets" if block_given?
        tweets.each_with_index do |t, i|
          r = exclude.any? { |i| t.text.include? i }
          if r == false
            puts "#{i+1} 👋  deletin #{t.text}" if block_given?
            client.destroy_status t
          end
        end
      rescue Twitter::Error::TooManyRequests => error
        sleep error.rate_limit.reset_in + 1
        retry
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
delete_my_tweets-0.1.1 lib/delete_my_tweets/twitter.rb
delete_my_tweets-0.1.0 lib/delete_my_tweets/twitter.rb