Nuke option for older comments

pull/23/head
David Trail 10 years ago
parent 2aeeb3309e
commit d1a0ffe0f5

@ -34,7 +34,7 @@ item = overview
whitelist = AskScience, TheCulture, redditdev, programming, charity whitelist = AskScience, TheCulture, redditdev, programming, charity
# If you want any specific posts to be whitelisted stick 'em in here # If you want any specific posts to be whitelisted stick 'em in here
whitelist_ids = abcdef whitelist_ids =
# If you set this then no editing or deleting will be done # If you set this then no editing or deleting will be done
# but the output from the program will be shown as an example # but the output from the program will be shown as an example
@ -42,10 +42,17 @@ trial_run = True
# Don't delete but *do* edit, could prove... interesting to see a comment # Don't delete but *do* edit, could prove... interesting to see a comment
# with 5000 upvotes and it's just a lorem ipsum! # with 5000 upvotes and it's just a lorem ipsum!
edit_only = True edit_only = False
# Ignore distinguished comments. # Ignore distinguished comments.
whitelist_distinguished = True whitelist_distinguished = True
# ignore gilded (gold) comments # Ignore gilded (gold) comments
whitelist_gilded = True whitelist_gilded = True
# Delete everything older that this date, **This ignores whitelists**.
# Can be used as a second deletion, as in "delete items older than 24 hours
# except on whitelisted subreddits but after 3 months delete everything.
nuke_hours = 0
# vim: syntax=config

@ -55,10 +55,11 @@ edit_only = config.getboolean('main', 'edit_only')
item = config.get('main', 'item') item = config.get('main', 'item')
whitelist_distinguished = config.getboolean('main', 'whitelist_distinguished') whitelist_distinguished = config.getboolean('main', 'whitelist_distinguished')
whitelist_gilded = config.getboolean('main', 'whitelist_gilded') whitelist_gilded = config.getboolean('main', 'whitelist_gilded')
nuke_hours = config.getint('main', 'nuke_hours')
_user = config.get('main', 'username') _user = config.get('main', 'username')
_pass = config.get('main', 'password') _pass = config.get('main', 'password')
r = praw.Reddit(user_agent="shreddit/3.1") r = praw.Reddit(user_agent="shreddit/3.2")
def login(user=None, password=None): def login(user=None, password=None):
@ -105,9 +106,11 @@ else:
for thing in things: for thing in things:
thing_time = datetime.fromtimestamp(thing.created_utc) thing_time = datetime.fromtimestamp(thing.created_utc)
# Delete things after after_time # Exclude items from being deleted unless past X hours.
after_time = datetime.utcnow() - timedelta(hours=hours) after_time = datetime.utcnow() - timedelta(hours=hours)
if thing_time > after_time: if thing_time > after_time:
if thing_time + timedelta(hours=nuke_hours) < datetime.utcnow():
pass
continue continue
# For edit_only we're assuming that the hours aren't altered. # For edit_only we're assuming that the hours aren't altered.
# This saves time when deleting (you don't edit already edited posts). # This saves time when deleting (you don't edit already edited posts).
@ -120,13 +123,15 @@ for thing in things:
thing.id in whitelist_ids: thing.id in whitelist_ids:
continue continue
if trial_run: if trial_run: # Don't do anything, trial mode!
# Don't actually perform any actions if verbose:
next print("Would have deleted {thing}: '{content}'".format(
thing=thing.id, content=thing))
continue
if whitelist_distinguished and thing.distinguished: if whitelist_distinguished and thing.distinguished:
next continue
if whitelist_gilded and thing.gilded: if whitelist_gilded and thing.gilded:
next continue
if clear_vote: if clear_vote:
thing.clear_vote() thing.clear_vote()

Loading…
Cancel
Save