Skip to content

Instantly share code, notes, and snippets.

@ajoyoommen
Created May 22, 2018 07:56
Show Gist options
  • Save ajoyoommen/e26cad0b14904f0984477ae11856745b to your computer and use it in GitHub Desktop.
Save ajoyoommen/e26cad0b14904f0984477ae11856745b to your computer and use it in GitHub Desktop.
Script to delete all tweets and favorites for a user.
import os
import tweepy
consumer_key = os.environ['CONSUMER_KEY']
consumer_secret = os.environ['CONSUMER_SECRET']
access_token = os.environ['ACCESS_TOKEN']
access_token_secret = os.environ['ACCESS_TOKEN_SECRET']
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
def delete_tweets():
for status in tweepy.Cursor(api.user_timeline).items():
try:
api.destroy_status(status.id)
print("Deleted:", status.id, status.text)
except:
print("Failed to delete:", status.id)
print('Deleted all tweets')
def delete_favorites():
for status in tweepy.Cursor(api.favorites).items():
try:
api.destroy_favorite(status.id)
print("> Deleted:", status.id, status.text)
except:
print("Failed to delete:", status.id)
print('Deleted all favorites')
if __name__ == '__main__':
delete_tweets()
delete_favorites()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment