Skip to content

Instantly share code, notes, and snippets.

@Epion003
Forked from vik-y/delete_all_tweets.py
Created September 17, 2016 12:26
Show Gist options
  • Select an option

  • Save Epion003/62150b6ea7d7c1448ac0425bd8f47451 to your computer and use it in GitHub Desktop.

Select an option

Save Epion003/62150b6ea7d7c1448ac0425bd8f47451 to your computer and use it in GitHub Desktop.
This script will delete all of the tweets in a specified account.
# This script will delete all of the tweets in the specified account.
# You may need to hit the 'more' button on the bottom of your twitter profile
# page every now and then as the script runs, this is due to a bug in twitter.
import twitter # Requires python-twitter library
username = 'your_username'
password = 'your_password'
api = twitter.Api(username=username, password=password)
api.SetCache(None) # Caching needs to be turned off
def delete_tweet(status_id):
"""Deletes tweet with matching status_id"""
api.DestroyStatus(status_id)
print "Deleted:", status_id
def batch_delete(batch_size = 200, username = username):
"""Fetches tweets in batches and calls delete_tweet on each one"""
print "Deleting all tweets from", username
batch = 0
while True: # Rinse and repeat
tweets = api.GetUserTimeline(username, count=batch_size) # Get batch of tweets
if tweets:
batch += 1 # Increment batch counter
print "\nProcessing batch", batch
for tweet in tweets:
delete_tweet(tweet.id)
else: # Exit if there aren't any tweets left
print "\nNo tweets left... Done"
break
batch_delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment