Last active
September 26, 2018 14:58
-
-
Save marydn/b82b483cdb858bbaf6b6fec4dc37e4e4 to your computer and use it in GitHub Desktop.
Revisions
-
marydn revised this gist
Sep 26, 2018 . 1 changed file with 10 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,10 +14,11 @@ # Delete tweets older than this ID max_id = 807213779268358144 dry_run = False # in case you want to filter status by dates startDate = datetime.datetime(2016, 1, 1, 0, 0, 0) endDate = datetime.datetime(2016, 12, 31, 0, 0, 0) # authentication auth = tweepy.OAuthHandler(consumer_key, consumer_secret) @@ -27,11 +28,11 @@ screen_name = api.verify_credentials().screen_name def get_statuses_by_dates(): tweets = [] tmpTweets = tweepy.Cursor(api.user_timeline).items() for tweet in tmpTweets: if tweet.created_at >= startDate and tweet.created_at <= endDate: tweets.append(tweet) return tweets @@ -40,17 +41,17 @@ def get_statuses_by_max_id(): return tweepy.Cursor(api.user_timeline, max_id = max_id).items() def print_status(tweet): print("Deleted: ", tweet.id, " - Date: ", tweet.created_at, " - ", tweet.text.encode('utf8')) def delete_status(tweet): try: if dry_run == False: api.destroy_status(tweet.id) print_status(tweet) except: print("Failed to delete: ", tweet.id) print("Deleting tweets for: @", screen_name) for status in get_statuses_by_dates(): delete_status(status) -
marydn created this gist
Sep 26, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ #!/usr/bin/python from __future__ import print_function import tweepy import itertools import datetime # OAuth application consumer_key = "<<CONSUMER_KEY>>" consumer_secret = "<<CONSUMER_SECRET>>" # OAuth account access_token = "<<ACCESS_TOKEN>>" access_token_secret = "<<ACCESS_TOKEN_SECRET>>" # Delete tweets older than this ID max_id = 807213779268358144 # in case you want to filter status by dates startDate = datetime.datetime(2015, 1, 1, 0, 0, 0) endDate = datetime.datetime(2010, 12, 31, 0, 0, 0) # authentication auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) screen_name = api.verify_credentials().screen_name def get_statuses_by_dates(from_date, to_date): tweets = [] tmpTweets = tweepy.Cursor(api.user_timeline).items() for tweet in tmpTweets: if tweet.created_at < to_date and tweet.created_at > from_date: tweets.append(tweet) return tweets def get_statuses_by_max_id(): return tweepy.Cursor(api.user_timeline, max_id = max_id).items() def print_status(tweet): print("Deleted: ", tweet.id, " - Date: ", tweet.created_at, " - ", tweet.text) def delete_status(tweet): try: api.destroy_status(tweet.id) print_status(tweet) except: print("Failed to delete: ", tweet.id) print("Deleting tweets for: @", screen_name) for status in get_statuses_by_dates(startDate, endDate): #delete_status(status) print_status(status)