Skip to content

Instantly share code, notes, and snippets.

@darbym
Last active January 3, 2019 19:56
Show Gist options
  • Save darbym/494137fcc17341bab3d21118a3337335 to your computer and use it in GitHub Desktop.
Save darbym/494137fcc17341bab3d21118a3337335 to your computer and use it in GitHub Desktop.
# using pipenv install the requirements of tweepy
# git clone https://github.com/tweepy/tweepy.git
# cd tweepy
# pipenv install -r requirements.txt
# edit and add your username
# run this command to launch
# pipenv run python delete_all_tweets.py
from __future__ import absolute_import, print_function
import tweepy
import sys
# == OAuth Authentication ==
#
# This mode of authentication is the new preferred way
# of authenticating with Twitter.
def auth():
# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "OAuth settings")
consumer_key=""
consumer_secret=""
# The access tokens can be found on your applications's Details
# page located at https://dev.twitter.com/apps (located
# under "Your access token")
access_token=""
access_token_secret=""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
# wait out the rate limiting
api = tweepy.API(auth,wait_on_rate_limit=True)
return api
# If the authentication was successful, you should
# see the name of the account print out
# This runs forever..
while True:
api = auth()
print(api.me().name)
username = "YOUR_USERNAME_HERE"
posts = 1
while posts > 0:
status_list = api.user_timeline(username)
posts = len(status_list)
for status in status_list:
print("removing %s" % status.id)
api.destroy_status(status.id)
# sometimes it fails. This reauths and try again.
print("no posts returned, reauth")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment