Created
August 4, 2021 05:35
-
-
Save rhnvrm/74e491a6f77c15feccc181ba85ae0c4a to your computer and use it in GitHub Desktop.
Interactively delete tweets from your timeline using tweepy
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
import tweepy | |
import os | |
import logging | |
import re | |
def create_api(): | |
consumer_key = os.getenv("CONSUMER_KEY") | |
consumer_secret = os.getenv("CONSUMER_SECRET") | |
access_token = os.getenv("ACCESS_TOKEN") | |
access_token_secret = os.getenv("ACCESS_SECRET") | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) | |
try: | |
api.verify_credentials() | |
except Exception as e: | |
logging.error("Error creating API", exc_info=True) | |
raise e | |
logging.info("API created") | |
return api | |
text = ''' | |
TEXTFORMATCHING | |
''' | |
def main(): | |
print("Retrieving timeline tweets") | |
api = create_api() | |
timeline = tweepy.Cursor(api.user_timeline).items() | |
for tweet in timeline: | |
cleaned = re.sub(r"http\S+", "", tweet.text) | |
print(tweet.id, cleaned) | |
if cleaned[:-5] in text: | |
print("MATCH!") | |
should_delete = input() | |
if should_delete == 'y': | |
print("deleting") | |
api.destroy_status(tweet.id) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment