From e682468eb3c9459b827b5a57cf95f0d39f9cec47 Mon Sep 17 00:00:00 2001 From: Dave Disser Date: Sun, 31 May 2015 15:09:19 -0700 Subject: [PATCH 1/3] Move trial_run check to after gilded & and distinguished check, since these comments would erroneously be indicated for deletion by trial mode. --- shreddit.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/shreddit.py b/shreddit.py index 88ed10d..b780bf1 100755 --- a/shreddit.py +++ b/shreddit.py @@ -123,15 +123,16 @@ for thing in things: thing.id in whitelist_ids: continue + if whitelist_distinguished and thing.distinguished: + continue + if whitelist_gilded and thing.gilded: + continue + if trial_run: # Don't do anything, trial mode! if verbose: print("Would have deleted {thing}: '{content}'".format( thing=thing.id, content=thing)) continue - if whitelist_distinguished and thing.distinguished: - continue - if whitelist_gilded and thing.gilded: - continue if clear_vote: thing.clear_vote() From c16b28e99c27fa781cb57faef87543a93238795d Mon Sep 17 00:00:00 2001 From: Dave Disser Date: Sun, 31 May 2015 15:10:50 -0700 Subject: [PATCH 2/3] Add max_score parameter to only delete comments with this score or less. --- shreddit.cfg.example | 5 +++++ shreddit.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/shreddit.cfg.example b/shreddit.cfg.example index e839e0f..e1a3fcf 100644 --- a/shreddit.cfg.example +++ b/shreddit.cfg.example @@ -55,4 +55,9 @@ whitelist_gilded = True # except on whitelisted subreddits but after 3 months delete everything. nuke_hours = 0 +# Only delete comments with this score or less, or delete all comments +# if this is not set. + +max_score = + # vim: syntax=config diff --git a/shreddit.py b/shreddit.py index b780bf1..317bbe8 100755 --- a/shreddit.py +++ b/shreddit.py @@ -56,6 +56,10 @@ item = config.get('main', 'item') whitelist_distinguished = config.getboolean('main', 'whitelist_distinguished') whitelist_gilded = config.getboolean('main', 'whitelist_gilded') nuke_hours = config.getint('main', 'nuke_hours') +try: + max_score = config.getint('main', 'max_score') +except ValueError: + max_score = None _user = config.get('main', 'username') _pass = config.get('main', 'password') @@ -127,6 +131,8 @@ for thing in things: continue if whitelist_gilded and thing.gilded: continue + if max_score is not None and thing.score > max_score: + continue if trial_run: # Don't do anything, trial mode! if verbose: From 7965ccad006ddf20f5e0de8b26218b88f9a45ccf Mon Sep 17 00:00:00 2001 From: Dave Disser Date: Sun, 31 May 2015 15:52:46 -0700 Subject: [PATCH 3/3] Add save_directory parameter to backup comment in JSON format. --- shreddit.cfg.example | 4 +++- shreddit.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/shreddit.cfg.example b/shreddit.cfg.example index e1a3fcf..85b1b20 100644 --- a/shreddit.cfg.example +++ b/shreddit.cfg.example @@ -57,7 +57,9 @@ nuke_hours = 0 # Only delete comments with this score or less, or delete all comments # if this is not set. - max_score = +# Save JSON encoded comment to this directory before deleting it. +save_directory = + # vim: syntax=config diff --git a/shreddit.py b/shreddit.py index 317bbe8..0581c54 100755 --- a/shreddit.py +++ b/shreddit.py @@ -60,10 +60,14 @@ try: max_score = config.getint('main', 'max_score') except ValueError: max_score = None +save_directory = config.get('main', 'save_directory') + _user = config.get('main', 'username') _pass = config.get('main', 'password') r = praw.Reddit(user_agent="shreddit/3.3") +if save_directory: + r.config.store_json_result = True def login(user=None, password=None): try: @@ -140,6 +144,12 @@ for thing in things: thing=thing.id, content=thing)) continue + if save_directory: + if not os.path.exists(save_directory): + os.makedirs(save_directory) + with open("%s/%s.json" % (save_directory, thing.id), "w") as fh: + json.dump(thing.json_dict, fh) + if clear_vote: thing.clear_vote()