Skip to content

Instantly share code, notes, and snippets.

@chand1012
Last active October 15, 2019 19:25
Show Gist options
  • Save chand1012/0918170dd29f994f072656f55bfb1b3b to your computer and use it in GitHub Desktop.
Save chand1012/0918170dd29f994f072656f55bfb1b3b to your computer and use it in GitHub Desktop.
Deletes tweets
import tweepy
def login(key, secret):
auth = tweepy.OAuthHandler(key, secret)
auth_url = auth.get_authorization_url()
verify = input(f"Enter your verification code after authenticating here: {auth_url}\n~$: ")
auth.get_access_token(verify)
return tweepy.API(auth)
def get_all_tweets(api, screen_name="chand0816"):
print("Getting all of your tweets...")
alltweets = []
new_tweets = api.user_timeline(screen_name=screen_name, count=200)
alltweets.extend(new_tweets)
oldest = alltweets[-1].id - 1
while len(new_tweets) > 0:
new_tweets = api.user_timeline(screen_name=screen_name, count=200, max_id=oldest)
alltweets.extend(new_tweets)
oldest = alltweets[-1].id - 1
return alltweets
def delete_tweets(api, tweets, match=[""]):
for tweet in tweets:
if any(thing in tweet.text.lower() for thing in match):
api.destroy_status(tweet.id)
print(f"Deleting tweet #{tweet.id}: {tweet.text}")
matches = []
key = ''
secret =''
api = login(key, secret)
tweets = get_all_tweets(api)
delete_tweets(api, tweets, matches)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment