-
-
Save Alexhuszagh/5cdeafcade51213d85dbd3700e77050b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
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+, 3.3+, Tweepy (http://pypi.python.org/pypi/tweepy/1.7.1) | |
@Author: Dave Jeffery | |
@Editor: John Troon | |
@Editor: Aex Huszagh | |
""" | |
import sys | |
import tweepy | |
consumer_key = "" | |
consumer_secret = "" | |
access_key = "" | |
access_secret = "" | |
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 delete_tweets(api): | |
'''Execute batch delete for Tweets''' | |
for status in tweepy.Cursor(api.user_timeline).items(): | |
try: | |
api.destroy_status(status.id) | |
print "Deleted:", status.id | |
except: | |
print "Failed to delete:", status.id | |
def delete_favorites(api): | |
'''Execute batch delete for Tweets''' | |
for status in tweepy.Cursor(api.favorites).items(): | |
try: | |
api.destroy_favorite(status.id) | |
print "Deleted:", status.id | |
except: | |
print "Failed to delete:", status.id | |
def check_delete(api): | |
'''Verify user wants to delete Tweets''' | |
print("You are about to Delete all tweets from the account @{}.".format(api.verify_credentials().screen_name)) | |
print("Does this sound ok? There is no undo! Type yes to carry out this action.") | |
if sys.version_info.major == 2: | |
do_delete = raw_input("> ") | |
else: | |
do_delete = input("> ") | |
return do_delete.lower() == 'yes' or do_delete.lower() == 'y' | |
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 | |
if check_delete(api): | |
delete_tweets(api) | |
delete_favorites(api) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment