|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
from re import sub
|
|
|
|
from re import sub
|
|
|
|
from random import shuffle, randint
|
|
|
|
from random import shuffle, randint
|
|
|
@ -52,6 +53,7 @@ clear_vote = config.getboolean('main', 'clear_vote')
|
|
|
|
trial_run = config.getboolean('main', 'trial_run')
|
|
|
|
trial_run = config.getboolean('main', 'trial_run')
|
|
|
|
edit_only = config.getboolean('main', 'edit_only')
|
|
|
|
edit_only = config.getboolean('main', 'edit_only')
|
|
|
|
item = config.get('main', 'item')
|
|
|
|
item = config.get('main', 'item')
|
|
|
|
|
|
|
|
keep_a_copy = config.get('main', 'keep_a_copy')
|
|
|
|
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')
|
|
|
|
nuke_hours = config.getint('main', 'nuke_hours')
|
|
|
@ -59,6 +61,8 @@ _user = config.get('main', 'username')
|
|
|
|
_pass = config.get('main', 'password')
|
|
|
|
_pass = config.get('main', 'password')
|
|
|
|
|
|
|
|
|
|
|
|
r = praw.Reddit(user_agent="shreddit/3.2")
|
|
|
|
r = praw.Reddit(user_agent="shreddit/3.2")
|
|
|
|
|
|
|
|
if keep_a_copy:
|
|
|
|
|
|
|
|
r.config.store_json_result = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def login(user=None, password=None):
|
|
|
|
def login(user=None, password=None):
|
|
|
@ -80,6 +84,12 @@ if not r.is_logged_in():
|
|
|
|
if verbose:
|
|
|
|
if verbose:
|
|
|
|
print("Logged in as {user}".format(user=r.user))
|
|
|
|
print("Logged in as {user}".format(user=r.user))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if keep_a_copy:
|
|
|
|
|
|
|
|
fname = str(datetime.utcnow()).replace(':','')+'.txt'
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
|
|
|
|
print("Saving {user}'s stuff in {name}".format(user=r.user, name=fname))
|
|
|
|
|
|
|
|
copy_file = open(fname, 'w')
|
|
|
|
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
if verbose:
|
|
|
|
print("Deleting messages before {time}.".format(
|
|
|
|
print("Deleting messages before {time}.".format(
|
|
|
|
time=datetime.now() - timedelta(hours=hours))
|
|
|
|
time=datetime.now() - timedelta(hours=hours))
|
|
|
@ -104,9 +114,10 @@ else:
|
|
|
|
raise Exception("Your deletion section is wrong")
|
|
|
|
raise Exception("Your deletion section is wrong")
|
|
|
|
|
|
|
|
|
|
|
|
for thing in things:
|
|
|
|
for thing in things:
|
|
|
|
|
|
|
|
# Seems to be in users's timezone. Unclear.
|
|
|
|
thing_time = datetime.fromtimestamp(thing.created_utc)
|
|
|
|
thing_time = datetime.fromtimestamp(thing.created_utc)
|
|
|
|
# Exclude items from being deleted unless past X hours.
|
|
|
|
# Exclude items from being deleted unless past X hours.
|
|
|
|
after_time = datetime.utcnow() - timedelta(hours=hours)
|
|
|
|
after_time = datetime.now() - timedelta(hours=hours)
|
|
|
|
if thing_time > after_time:
|
|
|
|
if thing_time > after_time:
|
|
|
|
if thing_time + timedelta(hours=nuke_hours) < datetime.utcnow():
|
|
|
|
if thing_time + timedelta(hours=nuke_hours) < datetime.utcnow():
|
|
|
|
pass
|
|
|
|
pass
|
|
|
@ -134,9 +145,25 @@ for thing in things:
|
|
|
|
|
|
|
|
|
|
|
|
if clear_vote:
|
|
|
|
if clear_vote:
|
|
|
|
thing.clear_vote()
|
|
|
|
thing.clear_vote()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#html is not playing well with json
|
|
|
|
|
|
|
|
d = thing.json_dict
|
|
|
|
|
|
|
|
if 'body_html' in d:
|
|
|
|
|
|
|
|
del d['body_html']
|
|
|
|
|
|
|
|
elif 'selftext_html' in d:
|
|
|
|
|
|
|
|
del d['selftext_html']
|
|
|
|
|
|
|
|
thing_json = json.dumps(d)
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(thing, Submission):
|
|
|
|
if isinstance(thing, Submission):
|
|
|
|
if verbose:
|
|
|
|
if verbose:
|
|
|
|
print(u'Deleting submission: #{id} {url}'.format(
|
|
|
|
print('Saving a copy of submission: #{id} {url}'.format(
|
|
|
|
|
|
|
|
id=thing.id,
|
|
|
|
|
|
|
|
url=thing.url)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if keep_a_copy:
|
|
|
|
|
|
|
|
copy_file.write(thing_json + '\n')
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
|
|
|
|
print('Deleting submission: #{id} {url}'.format(
|
|
|
|
id=thing.id,
|
|
|
|
id=thing.id,
|
|
|
|
url=thing.url)
|
|
|
|
url=thing.url)
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -153,6 +180,11 @@ for thing in things:
|
|
|
|
print('Editing {msg}'.format(msg=msg))
|
|
|
|
print('Editing {msg}'.format(msg=msg))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print('Editing and deleting {msg}'.format(msg=msg))
|
|
|
|
print('Editing and deleting {msg}'.format(msg=msg))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if keep_a_copy:
|
|
|
|
|
|
|
|
copy_file.write(thing_json + '\n')
|
|
|
|
thing.edit(replacement_text)
|
|
|
|
thing.edit(replacement_text)
|
|
|
|
if not edit_only:
|
|
|
|
if not edit_only:
|
|
|
|
thing.delete()
|
|
|
|
thing.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
copy_file.close()
|
|
|
|