Skip to content

Instantly share code, notes, and snippets.

@sei0o sei0o/remove.rb
Created Feb 26, 2020

Embed
What would you like to do?
require 'twitter'
require 'json'
client = Twitter::REST::Client.new do |conf|
conf.consumer_key = ""
conf.consumer_secret = ""
conf.access_token = ""
conf.access_token_secret = ""
end
# print "Query to list the tweets to be removed: "
# query = STDIN.gets.chomp
json = File.read "path/to/tweet.js" # get archive of tweets to delete older tweets
tweets = JSON.parse(json[25..-1])
deleted = IO.readlines "deleted.txt"
ids = tweets.select { |tweet|
!deleted.include?(tweet["id"]) &&
tweet["id"].to_i <= 1234567890
# Examples :
# tweet["full_text"].include?("appsfire")
# tweet["source"].include? "Flipboard"
#(tweet["entities"] && tweet["entities"]["urls"] || []).size >= 1 &&
# tweet["entities"]["urls"][0]["display_url"].include?("yahoo.co.")
}.each { |t|
id = t["id"]
begin
result = client.destroy_status [id]
puts "Tweet (ID: #{id}, text: #{t['full_text']}) was deleted"
rescue Twitter::Error::NotFound => err
puts "Tweet (ID: #{id}) Not Found"
File.open('deleted.txt', 'a') { |f| f.puts t["id"] }
rescue
puts "error"
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.