Skip to content

Instantly share code, notes, and snippets.

@Amenshawi
Forked from vik-y/delete_all_tweets.py
Last active May 25, 2020 02:34
Show Gist options
  • Select an option

  • Save Amenshawi/70938891a347b81ba32c65ed1a93a42f to your computer and use it in GitHub Desktop.

Select an option

Save Amenshawi/70938891a347b81ba32c65ed1a93a42f to your computer and use it in GitHub Desktop.
This script will delete some of the tweets in a specified account depending on the parameters given
# -*- coding: utf-8 -*-
"""
This script is forked from Vikas Yadav, @vik-y.
I made a few changes to make the script compatible with python3.
I also added the ability to specify a tweet to delete only tweets before it, this can be easily changed by changing
the parameters at line #60
@author: Amenshawi
-----------------------------------------------------------------------------
This script is forked originally from Dave Jeffery. The original implementation
was very slow and deleted around 2 tweets per second. Making it multithreaded I
am able to delete 30-50 tweets per second.
@author: vik-y
----------------------------------------------------------------------------
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 tweepy
import _thread
consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""
def deleteThread(api, objectId):
try:
api.destroy_status(objectId)
print ("Deleted:", objectId)
except:
print ("Failed to delete 000:", objectId)
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)
return tweepy.API(auth)
def batch_delete(api):
print ("You are about to Delete all tweets from the account @%s." % api.verify_credentials().screen_name)
## Change the Max_id value to the latest tweet you don't want it to be deleted,
# any previous tweets will be deleted ##
for status in tweepy.Cursor(api.user_timeline, max_id=,).items():
try:
_thread.start_new_thread(deleteThread, (api, status.id, ))
except:
print ("Failed to delete:", status.id)
if __name__ == "__main__":
## authorize twitter, initialize tweepy ##
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
print ("Authenticated as: %s" % api.me().screen_name)
batch_delete(api)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment