Skip to content

Instantly share code, notes, and snippets.

@hodgesmr
Created November 22, 2022 16:03
Show Gist options
  • Save hodgesmr/dce1b1e6f7023af5d9adbea7fd3d6c49 to your computer and use it in GitHub Desktop.
Save hodgesmr/dce1b1e6f7023af5d9adbea7fd3d6c49 to your computer and use it in GitHub Desktop.
delete tweets with tweepy
import json
import tweepy
# 1. Download your twitter archive
# 2. fix the first line of tweets.js to be proper json
# 3. Get twitter API creds
# 4. fix all the SETMEs in here
# 5. run this
CONSUMER_KEY = 'SETME'
CONSUMER_SECRET = 'SETME'
ACCESS_TOKEN = 'SETME'
ACCESS_TOKEN_SECRET = 'SETME'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth, wait_on_rate_limit=True)
with open('tweets.js', 'r') as tweet_file:
tweet_data = json.load(tweet_file)
omit = {
'SETME',
'SETME'
}
for tweet in tweet_data:
tweet_id = tweet['tweet']['id']
if tweet_id not in omit:
try:
api.destroy_status(tweet_id)
print('Deleted: {}'.format(tweet_id))
except Exception as e: # idk what will happen here
print('ERROR: {} : {}'.format(tweet_id, e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment