Skip to content

Instantly share code, notes, and snippets.

@sadanalog
Forked from davej/delete_all_tweets.py
Created September 24, 2018 00:23
Show Gist options
  • Save sadanalog/ca53f3c88613f2e09178a294be11ff7d to your computer and use it in GitHub Desktop.
Save sadanalog/ca53f3c88613f2e09178a294be11ff7d to your computer and use it in GitHub Desktop.

Revisions

  1. @davej davej revised this gist Jan 25, 2014. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -33,8 +33,11 @@ def batch_delete(api):
    do_delete = raw_input("> ")
    if do_delete.lower() == 'yes':
    for status in tweepy.Cursor(api.user_timeline).items():
    api.destroy_status(status.id)
    print "Deleted:", status.id
    try:
    api.destroy_status(status.id)
    print "Deleted:", status.id
    except:
    print "Failed to delete:", status.id

    if __name__ == "__main__":
    api = oauth_login(CONSUMER_KEY, CONSUMER_SECRET)
  2. @davej davej revised this gist Aug 15, 2011. 1 changed file with 34 additions and 28 deletions.
    62 changes: 34 additions & 28 deletions delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -1,37 +1,43 @@
    # -*- coding: utf-8 -*-
    """
    @requirements: python-twitter (http://code.google.com/p/python-twitter/) and simplejson (http://code.google.com/p/simplejson/)
    @author: Dave Jeffery
    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.
    You will need to get a consumer key and consumer secret token to use this
    script, you can do so by registering a twitter application at https://dev.twitter.com/apps
    @requirements: Python 2.5+, Tweepy (http://pypi.python.org/pypi/tweepy/1.7.1)
    @author: Dave Jeffery
    """

    import twitter, urllib2

    def delete_tweet(api, status_id):
    """Deletes tweet with matching status_id"""
    api.DestroyStatus(status_id)
    print "Deleted:", status_id

    def batch_delete(username, password, batch_size=200):
    """Fetches tweets in batches and calls delete_tweet on each one"""
    api = twitter.Api(username, password)
    api.SetCache(None) # Caching needs to be turned off
    import tweepy

    CONSUMER_KEY = 'XXX'
    CONSUMER_SECRET = 'XXX'

    def oauth_login(consumer_key, consumer_secret):
    """Authenticate with twitter using OAuth"""

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth_url = auth.get_authorization_url()

    verify_code = raw_input("Authenticate at %s and then enter you verification code here > " % auth_url)
    auth.get_access_token(verify_code)

    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
    print "\nProcessing batch", batch
    for tweet in tweets:
    delete_tweet(api, tweet.id)
    elif not tweets:
    print "\nNo tweets left... Done"
    break
    return tweepy.API(auth)

    if __name__ == "__main__":
    batch_delete(username="user", password="pass")
    def batch_delete(api):
    print "You are about to Delete all tweets from the account @%s." % api.verify_credentials().screen_name
    print "Does this sound ok? There is no undo! Type yes to carry out this action."
    do_delete = raw_input("> ")
    if do_delete.lower() == 'yes':
    for status in tweepy.Cursor(api.user_timeline).items():
    api.destroy_status(status.id)
    print "Deleted:", status.id

    if __name__ == "__main__":
    api = oauth_login(CONSUMER_KEY, CONSUMER_SECRET)
    print "Authenticated as: %s" % api.me().screen_name

    batch_delete(api)
  3. @davej davej revised this gist May 19, 2009. 1 changed file with 20 additions and 18 deletions.
    38 changes: 20 additions & 18 deletions delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -1,35 +1,37 @@
    # 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'
    # -*- coding: utf-8 -*-
    """
    @requirements: python-twitter (http://code.google.com/p/python-twitter/) and simplejson (http://code.google.com/p/simplejson/)
    @author: Dave Jeffery
    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.
    """

    api = twitter.Api(username=username, password=password)
    api.SetCache(None) # Caching needs to be turned off
    import twitter, urllib2

    def delete_tweet(status_id):
    def delete_tweet(api, status_id):
    """Deletes tweet with matching status_id"""
    api.DestroyStatus(status_id)
    print "Deleted:", status_id

    def batch_delete(batch_size = 200, username = username):
    def batch_delete(username, password, batch_size=200):
    """Fetches tweets in batches and calls delete_tweet on each one"""
    api = twitter.Api(username, password)
    api.SetCache(None) # Caching needs to be turned off

    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
    batch += 1
    print "\nProcessing batch", batch
    for tweet in tweets:
    delete_tweet(tweet.id)
    else: # Exit if there aren't any tweets left
    delete_tweet(api, tweet.id)
    elif not tweets:
    print "\nNo tweets left... Done"
    break

    batch_delete()
    if __name__ == "__main__":
    batch_delete(username="user", password="pass")
  4. @davej davej revised this gist May 18, 2009. 1 changed file with 21 additions and 13 deletions.
    34 changes: 21 additions & 13 deletions delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,12 @@
    # 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'
    count = 200 # Number of statuses in a batch. Twitter API wont allow more than 200


    api = twitter.Api(username=username, password=password)
    api.SetCache(None) # Caching needs to be turned off

    @@ -16,12 +15,21 @@ def delete_tweet(status_id):
    api.DestroyStatus(status_id)
    print "Deleted:", status_id

    batch = 0 # initialise batch counter
    while True: # Rinse and repeat
    batch += 1 # Increment batch counter
    print "\nProcessing batch", batch
    tweets = api.GetUserTimeline(username, count=count) # Get batch of tweets
    if not tweets: break # Exit if there aren't any tweets left
    [delete_tweet(tweet.id) for tweet in tweets] # Delete tweets in this batch

    print "\nDone"
    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()
  5. @davej davej revised this gist May 18, 2009. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -14,14 +14,14 @@
    def delete_tweet(status_id):
    """Deletes tweet with matching status_id"""
    api.DestroyStatus(status_id)
    print "Deleted:", str(status_id)

    batch = 0
    print "Deleted:", status_id
    batch = 0 # initialise batch counter
    while True: # Rinse and repeat
    batch += 1
    print "\nProcessing batch ", str(batch)
    batch += 1 # Increment batch counter
    print "\nProcessing batch", batch
    tweets = api.GetUserTimeline(username, count=count) # Get batch of tweets
    if not tweets: break # Exit if there aren't any tweets left
    [delete_tweet(tweet.id) for tweet in tweets] # Delete tweets in batch
    [delete_tweet(tweet.id) for tweet in tweets] # Delete tweets in this batch

    print "\nDone"
    print "\nDone"
  6. @davej davej revised this gist May 18, 2009. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -14,12 +14,12 @@
    def delete_tweet(status_id):
    """Deletes tweet with matching status_id"""
    api.DestroyStatus(status_id)
    print "Deleted: " + str(status_id)
    print "Deleted:", str(status_id)

    batch = 0
    while True: # Rinse and repeat
    batch += 1
    print "\nProcessing batch " + str(batch)
    print "\nProcessing batch ", str(batch)
    tweets = api.GetUserTimeline(username, count=count) # Get batch of tweets
    if not tweets: break # Exit if there aren't any tweets left
    [delete_tweet(tweet.id) for tweet in tweets] # Delete tweets in batch
  7. @davej davej revised this gist May 18, 2009. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -16,12 +16,12 @@ def delete_tweet(status_id):
    api.DestroyStatus(status_id)
    print "Deleted: " + str(status_id)

    batch = 0 # initialise batch counter
    batch = 0
    while True: # Rinse and repeat
    batch += 1 # Increment batch counter
    batch += 1
    print "\nProcessing batch " + str(batch)
    tweets = api.GetUserTimeline(username, count=count) # Get batch of tweets
    if not tweets: break # Exit if there aren't any tweets left
    [delete_tweet(tweet.id) for tweet in tweets] # Delete tweets in this batch
    [delete_tweet(tweet.id) for tweet in tweets] # Delete tweets in batch

    print "\nDone"
  8. @davej davej revised this gist May 18, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # 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.
    # page every now and then as the script runs, this is due to a bug in twitter.

    import twitter # Requires python-twitter library

  9. @davej davej revised this gist May 18, 2009. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # This script will delete all of the tweets in the specified account.
    # You may need to hit the more button every now and then as the script runs
    # this is due to a bug in twitter.com
    # 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

  10. @davej davej revised this gist May 18, 2009. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    # 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 every now and then as the script runs
    # this is due to a bug in twitter.com

    import twitter # Requires python-twitter library

  11. @davej davej revised this gist May 18, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # This script will delete all of the tweets in a specified account

    import twitter
    import twitter # Requires python-twitter library

    username = 'your_username'
    password = 'your_password'
  12. @davej davej created this gist May 18, 2009.
    25 changes: 25 additions & 0 deletions delete_all_tweets.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    # This script will delete all of the tweets in a specified account

    import twitter

    username = 'your_username'
    password = 'your_password'
    count = 200 # Number of statuses in a batch. Twitter API wont allow more than 200

    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: " + str(status_id)

    batch = 0 # initialise batch counter
    while True: # Rinse and repeat
    batch += 1 # Increment batch counter
    print "\nProcessing batch " + str(batch)
    tweets = api.GetUserTimeline(username, count=count) # Get batch of tweets
    if not tweets: break # Exit if there aren't any tweets left
    [delete_tweet(tweet.id) for tweet in tweets] # Delete tweets in this batch

    print "\nDone"