-
-
Save mattly/0725df1cd12fe5e4985b to your computer and use it in GitHub Desktop.
nuke your twitter history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Modified from https://gist.github.com/robinsloan/3688616 | |
# This version will nuke your entire twitter history past a certain threshold. | |
# It requires you to download your archive from twitter and put "tweets.csv" | |
# in the same directory as this script. | |
require 'rubygems' | |
require 'twitter' | |
require 'json' | |
require 'faraday' | |
require 'csv' | |
require 'time' | |
# things you must configure | |
TWITTER_USER = "your user name here" | |
# get these from dev.twitter.com | |
CONSUMER_KEY = "" | |
CONSUMER_SECRET = "" | |
OAUTH_TOKEN = "aka access key" | |
OAUTH_TOKEN_SECRET = "aka access secret" | |
# things you might want to change | |
MAX_AGE_IN_DAYS = 10 # anything older than this is deleted | |
DELAY_BETWEEN_DELETES = 0.5 # in seconds | |
DELAY_BETWEEN_REQS = 45 | |
# save tweets that have been massively favorited or retweeted??? nah. all is vanity. | |
# "points" are number of favs plus the number of RTs | |
POINT_THRESHOLD = 9999 | |
# don't delete these (maybe a pinned tweet? an old favorite? whatever) | |
IDS_TO_SAVE_FOREVER = [] | |
# you don't need to mess with this | |
API_TWEET_MAX = 3200 | |
TWEETS_PER_PAGE = 200 # api max is 250 or something... 200 seems like a nice round number | |
NUM_PAGES = (API_TWEET_MAX / TWEETS_PER_PAGE).to_i | |
MAX_AGE_IN_SECONDS = MAX_AGE_IN_DAYS*24*60*60 | |
NOW_IN_SECONDS = Time.now | |
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 | |
def delete_from_twitter(tweet,client) | |
begin | |
client.destroy_status(tweet.id) | |
rescue StandardError => e | |
puts e.inspect | |
puts "Error deleting #{tweet.id} " | |
# exit | |
else | |
puts "Deleted" | |
end | |
end | |
timeline = CSV.read("tweets.csv") | |
keys = timeline.shift | |
puts "Got #{timeline.size} tweets" | |
puts "" | |
keep_count = 0 | |
del_count = 0 | |
to_lookup = timeline.select do |tweet| | |
NOW_IN_SECONDS - Time.parse(tweet[3]) > MAX_AGE_IN_SECONDS | |
end | |
to_lookup.each_slice(100) do |set| | |
ids = set.map {|tweet| tweet[0] } | |
puts "Getting #{ids.size} tweets, #{ids.first} .. #{ids.last}" | |
tweets = client.statuses(ids) | |
received = tweets.size | |
puts "Got #{received} tweets" | |
puts "" | |
to_delete = tweets.select do |tweet| | |
tweet.favorite_count + tweet.retweet_count < POINT_THRESHOLD || tweet.text.match(/^RT/) | |
end | |
keep_count += (received - to_delete.size) | |
to_delete.each do |tweet| | |
del_count += 1 | |
puts "Deleting tweet from #{tweet.created_at} with #{tweet.favorite_count} faves, #{tweet.retweet_count} RTs:" | |
puts tweet.text | |
puts "" | |
delete_from_twitter(tweet, client) | |
end | |
sleep DELAY_BETWEEN_DELETES * 10 | |
puts "Ignored #{keeping} tweets, deleted #{to_delete.size}" | |
end | |
puts "deleted #{del_count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment