Skip to content

Instantly share code, notes, and snippets.

@Rayraegah
Created July 23, 2018 23:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rayraegah/7bc3542b46debb57f81eff94cec61f8a to your computer and use it in GitHub Desktop.
Save Rayraegah/7bc3542b46debb57f81eff94cec61f8a to your computer and use it in GitHub Desktop.
Nuke My Tweets
#!/bin/python3
"""
A python script to nuke tweets in your account using tweet history
@requirements: tweepy, python-dotenv
"""
from os import getenv
from os.path import join, dirname
from dotenv import load_dotenv
import tweepy
import csv
# Load env file
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
# Access env variables
consumer_key = getenv('CONSUMER_KEY')
consumer_secret = getenv('CONSUMER_SECRET')
access_token = getenv('ACCESS_TOKEN')
access_token_secret = getenv('ACCESS_TOKEN_SECRET')
tweets_to_keep = getenv('TWEETS_TO_KEEP').split(',')
tweets_csv = getenv('PATH_TO_TWEETS')
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
print('OAuth request sent')
api = tweepy.API(auth)
print('OAuth successful, now loading tweets archive')
with open(tweets_csv, 'r') as f:
reader = csv.reader(f)
# Skip header
next(reader, None)
# Convert CSV to list
tweets_list = list(reader)
print('Nuking...')
for tweet in tweets_list:
# tweet[0] is the tweet_id column
tweet_id = tweet[0]
if (tweet_id in tweets_to_keep):
# Do not delete tweet
print('[ 0 ] tweet with id %s' %(tweet_id))
else:
# Delete the tweet
api.destroy_status(tweet_id)
print('[ - ] tweet with id %s' %(tweet_id))
print('Mission complete!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment