|
|
|
@ -10,7 +10,8 @@ from simpleconfigparser import simpleconfigparser
|
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
|
|
import praw
|
|
|
|
|
from praw.errors import InvalidUser, InvalidUserPass, RateLimitExceeded
|
|
|
|
|
from praw.errors import InvalidUser, InvalidUserPass, RateLimitExceeded, \
|
|
|
|
|
HTTPException
|
|
|
|
|
from praw.objects import Comment, Submission
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -67,11 +68,17 @@ 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")
|
|
|
|
|
r = praw.Reddit(user_agent="shreddit/4.0")
|
|
|
|
|
if save_directory:
|
|
|
|
|
r.config.store_json_result = True
|
|
|
|
|
|
|
|
|
|
def login(user=None, password=None):
|
|
|
|
|
try:
|
|
|
|
|
# This is OAuth 2
|
|
|
|
|
r.refresh_access_information()
|
|
|
|
|
if verbose:
|
|
|
|
|
print("Logged in with OAuth.")
|
|
|
|
|
except HTTPException:
|
|
|
|
|
try:
|
|
|
|
|
if user and password:
|
|
|
|
|
r.login(_user, _pass)
|
|
|
|
@ -88,7 +95,7 @@ if not r.is_logged_in():
|
|
|
|
|
login(user=_user, password=_pass)
|
|
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
|
print("Logged in as {user}".format(user=r.user))
|
|
|
|
|
print("Logged in as {user}.".format(user=r.user))
|
|
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
|
print("Deleting messages before {time}.".format(
|
|
|
|
@ -103,17 +110,18 @@ if verbose and whitelist:
|
|
|
|
|
subs=', '.join(whitelist))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
things = []
|
|
|
|
|
if item == "comments":
|
|
|
|
|
things = r.user.get_comments(limit=None, sort=sort)
|
|
|
|
|
elif item == "submitted":
|
|
|
|
|
things = r.user.get_submitted(limit=None, sort=sort)
|
|
|
|
|
elif item == "overview":
|
|
|
|
|
things = r.user.get_overview(limit=None, sort=sort)
|
|
|
|
|
else:
|
|
|
|
|
def get_things(after=None):
|
|
|
|
|
if item == "comments":
|
|
|
|
|
return r.user.get_comments(limit=None, sort=sort)
|
|
|
|
|
elif item == "submitted":
|
|
|
|
|
return r.user.get_submitted(limit=None, sort=sort)
|
|
|
|
|
elif item == "overview":
|
|
|
|
|
return r.user.get_overview(limit=None, sort=sort)
|
|
|
|
|
else:
|
|
|
|
|
raise Exception("Your deletion section is wrong")
|
|
|
|
|
|
|
|
|
|
for thing in things:
|
|
|
|
|
def remove_things(things):
|
|
|
|
|
for thing in things:
|
|
|
|
|
# Seems to be in users's timezone. Unclear.
|
|
|
|
|
thing_time = datetime.fromtimestamp(thing.created_utc)
|
|
|
|
|
# Exclude items from being deleted unless past X hours.
|
|
|
|
@ -178,3 +186,7 @@ for thing in things:
|
|
|
|
|
thing.edit(replacement_text)
|
|
|
|
|
if not edit_only:
|
|
|
|
|
thing.delete()
|
|
|
|
|
|
|
|
|
|
things = get_things()
|
|
|
|
|
remove_things(things)
|
|
|
|
|
|
|
|
|
|