From 2658074f475ddfb864167b76811c3dbf81b7336a Mon Sep 17 00:00:00 2001 From: x89 Date: Wed, 25 Mar 2015 17:45:03 +0000 Subject: [PATCH] Merged changed from pteek with fixes. --- .gitignore | 3 +++ shreddit.cfg.example | 6 +++--- shreddit.py | 11 ++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 5d4d81c..48e09f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +2015*.txt +2016*.txt +2017*.txt *.cfg *.pyc shreddit.conf diff --git a/shreddit.cfg.example b/shreddit.cfg.example index 2fe9306..f34a167 100644 --- a/shreddit.cfg.example +++ b/shreddit.cfg.example @@ -28,9 +28,6 @@ clear_vote = False # Overview: both submissions and comments. Comments / Submitted are as expected. item = overview -# Save comments and posts before deleting them? -keep_a_copy = True - # Anything in this list won't be deleted, coma delimited # spaces should work as .strip() is called after splitting # on comma. @@ -58,4 +55,7 @@ whitelist_gilded = True # except on whitelisted subreddits but after 3 months delete everything. nuke_hours = 0 +# Save a copy to disk of comments and posts before deleting them. +keep_a_copy = False + # vim: syntax=config diff --git a/shreddit.py b/shreddit.py index 944ed06..8db7bab 100755 --- a/shreddit.py +++ b/shreddit.py @@ -89,7 +89,7 @@ if keep_a_copy: if verbose: print("Saving {user}'s stuff in {name}".format(user=r.user, name=fname)) copy_file = open(fname, 'w') - + if verbose: print("Deleting messages before {time}.".format( time=datetime.now() - timedelta(hours=hours)) @@ -153,9 +153,9 @@ for thing in things: elif 'selftext_html' in d: del d['selftext_html'] thing_json = json.dumps(d) - + if isinstance(thing, Submission): - if verbose && keep_a_copy: + if verbose and keep_a_copy: print('Saving a copy of submission: #{id} {url}'.format( id=thing.id, url=thing.url) @@ -180,11 +180,12 @@ for thing in things: print('Editing {msg}'.format(msg=msg)) else: print('Editing and deleting {msg}'.format(msg=msg)) - + if keep_a_copy: copy_file.write(thing_json + '\n') thing.edit(replacement_text) if not edit_only: thing.delete() -copy_file.close() +if keep_a_copy: + copy_file.close()