Skip to content

Instantly share code, notes, and snippets.

@camtheman256
Created June 9, 2019 21:14
Show Gist options
  • Save camtheman256/d20ddd3c1449f487e748c22b761d6bed to your computer and use it in GitHub Desktop.
Save camtheman256/d20ddd3c1449f487e748c22b761d6bed to your computer and use it in GitHub Desktop.
Couple methods to delete all tweets and likes with tweepy API
#!/usr/bin/python3
# ================================================
# Tips: pip3 install tweepy before you get started
# You'll also need to set up a developer account
# and application on developer.twitter.com in
# order to get the necessary keys/secrets
#
# Enjoy! Cameron Kleiman, 2019
# ================================================
import tweepy
import threading
import sys, traceback
api_key = ""
api_secret = ""
access_token = ""
access_secret = ""
auth = tweepy.OAuthHandler(api_key, api_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
def run_deletion():
def delete_tweet(api, status_id):
try:
api.destroy_status(status_id)
print("Deleted tweet: ", status_id)
except:
print("Could not delete tweet: ", status_id)
index = 0
for tweet in tweepy.Cursor(api.user_timeline).items():
try:
t = threading.Thread(target=delete_tweet, args=(api, tweet.id))
index += 1
print("Running deletion number %s" % index)
t.start()
except:
print(traceback.print_exception(*sys.exc_info()))
print("Deletion could not start on tweet %s" % tweet.id)
def run_unlike():
def unlike_tweet(api, status_id):
try:
api.destroy_favorite(status_id)
print("Removed favorite: ", status_id)
except:
print("Could not unfavorite tweet: ", status_id)
index = 0
for tweet in tweepy.Cursor(api.favorites, id="cmk256").items():
try:
t = threading.Thread(target=unlike_tweet, args=(api, tweet.id))
index += 1
print("Running unlike number %s" % index)
t.start()
except:
print(traceback.print_exception(*sys.exc_info()))
print("Unfavorite could not start on tweet %s" % tweet.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment