Skip to content

Instantly share code, notes, and snippets.

@winstxnhdw
Last active October 20, 2022 15:52
Show Gist options
  • Save winstxnhdw/63fff3716951917fbabde290e573926c to your computer and use it in GitHub Desktop.
Save winstxnhdw/63fff3716951917fbabde290e573926c to your computer and use it in GitHub Desktop.
Twitter bot that automatically sends all your cringey tweets to oblivion.
import tweepy
from traceback import print_exc
from re import sub
def oauth_login(consumer_key, consumer_secret):
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth_url = auth.get_authorization_url()
print(f'\nAuthenticate at: {auth_url}')
verify_code = input('Enter you verification code here: ')
auth.get_access_token(verify_code)
return tweepy.API(auth, wait_on_rate_limit=True)
def batch_delete(api):
print(f'You are about to permanently delete all {api.verify_credentials().statuses_count} tweets from your account.')
print('Type 'yes' to carry out this action.')
allow_delete = input('> ')
if allow_delete.lower() == 'yes':
for status in tweepy.Cursor(api.user_timeline).items():
try:
api.destroy_status(status.id)
print('Deleted:', status.id)
except tweepy.TweepError:
print_exc()
print('Failed to delete:', status.id)
print('All deletable tweets have been deleted. Have a nice day!')
def main():
clean_string = lambda input: sub('^ +', '', input)
consumer_key = clean_string(input('Enter your Twitter consumer key: '))
consumer_secret = clean_string(input('Enter your Twitter consumer secret: '))
api = oauth_login(consumer_key, consumer_secret)
print(f'\nWelcome {api.me().screen_name}!')
batch_delete(api)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment