Skip to content

Commit

Permalink
fix delete comments and posts
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPowerScripts committed May 8, 2020
1 parent d801e93 commit 5a4a4e7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
53 changes: 40 additions & 13 deletions src/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,21 @@ def submission_timespan():

def delete_comments():
count = 0
for comment in api.redditor(api.user.me().name).new(limit=500):
if comment.score <= SCORE_THRESHOLD:
for item in api.redditor(api.user.me().name).new(limit=500):
if item.score <= SCORE_THRESHOLD:

if isinstance(item, praw.models.Comment):
log.info(
"deleting comment(id={id}, body={body}, score={score}, subreddit={sub}|{sub_id})".format(
id=comment.id,
body=comment.body,
score=comment.score,
sub=comment.subreddit_name_prefixed,
sub_id=comment.subreddit_id,
id=item.id,
body=item.body,
score=item.score,
sub=item.subreddit_name_prefixed,
sub_id=item.subreddit_id,
)
)
try:
comment.delete()
item.delete()
except praw.exceptions.APIException as e:
raise e
except Exception as e:
Expand All @@ -217,11 +219,36 @@ def delete_comments():
)
)
count += 1
log.info(
"deleted {number} comments with less than {threshold} vote".format(
number=count, threshold=SCORE_THRESHOLD
)
)
log.info(
"deleted {number} comments with less than {threshold} vote".format(
number=count, threshold=SCORE_THRESHOLD
)
)
else:
log.info(
"deleting submission(id={id}, score={score}, subreddit={sub}|{sub_id})".format(
id=item.id,
score=item.score,
sub=item.subreddit_name_prefixed,
sub_id=item.subreddit_id,
)
)
try:
item.delete()
except praw.exceptions.APIException as e:
raise e
except Exception as e:
log.info(
"unable to delete submission(id={id}), skip...\n{error}".format(
id=item.id, error=e.message
)
)
count += 1
log.info(
"deleted {number} submission with less than {threshold} vote".format(
number=count, threshold=SCORE_THRESHOLD
)
)


def shadow_check():
Expand Down
15 changes: 7 additions & 8 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@
# Logging options
LOG_LEARNED_COMMENTS = False

if get_args().sublist: # Prefer subreddit list from envars
SUBREDDIT_LIST = get_args().sublist.strip().split(",")
log.info("Getting subreddit list from envar or args")
else:
log.info('Using subreddit list from utils.py')

log.info(SUBREDDIT_LIST)

subreddit = collections.namedtuple(
"Subreddit", ["name", "rank", "url", "subscribers", "type"]
)
Expand All @@ -71,6 +63,13 @@ def get_args():
parser.add_argument('-l','--sublist', default=os.environ.get('REDDIT_SUBREDDITS'))
return parser.parse_args()

if get_args().sublist: # Prefer subreddit list from envars
SUBREDDIT_LIST = get_args().sublist.strip().split(",")
log.info("Getting subreddit list from envar or args")
else:
log.info('Using subreddit list from utils.py')

log.info(SUBREDDIT_LIST)

def get_current_epoch():
return int(time.time())
Expand Down

0 comments on commit 5a4a4e7

Please sign in to comment.