first rework
This commit is contained in:
parent
b76212bc1d
commit
ae271d3374
1 changed files with 39 additions and 44 deletions
51
tweetdelete.py
Normal file → Executable file
51
tweetdelete.py
Normal file → Executable file
|
@ -1,43 +1,40 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import tweepy
|
import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
# options
|
import toml
|
||||||
test_mode = False
|
import tweepy
|
||||||
verbose = True
|
from xdg import xdg_config_home
|
||||||
delete_tweets = True
|
|
||||||
days_to_keep = 30
|
|
||||||
|
|
||||||
tweets_to_save = [
|
# options
|
||||||
# 1234567890
|
twitter_config = toml.load(os.path.join(xdg_config_home(), "twitter.toml"))
|
||||||
]
|
test_mode = twitter_config["test_mode"] if "test_mode" in twitter_config else False
|
||||||
|
verbose = twitter_config["verbose"] if "verbose" in twitter_config else False
|
||||||
|
days_to_keep = twitter_config["days_to_keep"] if "days_to_keep" in twitter_config else 30
|
||||||
|
tweets_to_save = twitter_config["tweets_to_save"] if "tweets_to_save" in twitter_config else []
|
||||||
|
secrets = twitter_config["secrets"]
|
||||||
|
|
||||||
# auth and api
|
# auth and api
|
||||||
consumer_key = 'FOOBAR'
|
auth = tweepy.OAuthHandler(secrets['api_key'], secrets['api_key_secret'])
|
||||||
consumer_secret = 'FOOBAR'
|
auth.set_access_token(secrets['access_token'], secrets['access_token_secret'])
|
||||||
access_token = 'FOOBAR'
|
|
||||||
access_token_secret = 'FOOBAR'
|
|
||||||
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
|
|
||||||
auth.set_access_token(access_token, access_token_secret)
|
|
||||||
api = tweepy.API(auth)
|
api = tweepy.API(auth)
|
||||||
|
|
||||||
# set cutoff date, use utc to match twitter
|
# set cutoff date, use utc to match twitter
|
||||||
cutoff_date = datetime.utcnow() - timedelta(days=days_to_keep)
|
cutoff_date = datetime.utcnow() - timedelta(days=days_to_keep)
|
||||||
|
|
||||||
# delete old tweets
|
# get all timeline tweets
|
||||||
if delete_tweets:
|
print("Retrieving timeline tweets")
|
||||||
# get all timeline tweets
|
timeline = tweepy.Cursor(api.user_timeline).items()
|
||||||
print("Retrieving timeline tweets")
|
deletion_count = 0
|
||||||
timeline = tweepy.Cursor(api.user_timeline).items()
|
ignored_count = 0
|
||||||
deletion_count = 0
|
|
||||||
ignored_count = 0
|
|
||||||
|
|
||||||
for tweet in timeline:
|
for tweet in timeline:
|
||||||
# where tweets are not in save list and older than cutoff date
|
# where tweets are not in save list and older than cutoff date
|
||||||
if tweet.id not in tweets_to_save and tweet.created_at < cutoff_date:
|
if tweet.id not in tweets_to_save and tweet.created_at < cutoff_date:
|
||||||
if verbose:
|
if verbose:
|
||||||
print("Deleting %d: [%s] %s" % (tweet.id, tweet.created_at, tweet.text))
|
print("Deleting %d: [%s] %s" %
|
||||||
|
(tweet.id, tweet.created_at, tweet.text))
|
||||||
if not test_mode:
|
if not test_mode:
|
||||||
api.destroy_status(tweet.id)
|
api.destroy_status(tweet.id)
|
||||||
|
|
||||||
|
@ -45,6 +42,4 @@ if delete_tweets:
|
||||||
else:
|
else:
|
||||||
ignored_count += 1
|
ignored_count += 1
|
||||||
|
|
||||||
print("Deleted %d tweets, ignored %d" % (deletion_count, ignored_count))
|
print("Deleted %d tweets, ignored %d" % (deletion_count, ignored_count))
|
||||||
else:
|
|
||||||
print("Not deleting tweets")
|
|
||||||
|
|
Loading…
Reference in a new issue