Merge pull request #75 from scott-hand/master

Adds multireddit white and black lists
pull/77/head
Scott Hand 8 years ago committed by GitHub
commit d511acbfd5

@ -4,7 +4,7 @@ from setuptools import setup
from codecs import open
from os import path
VERSION = "3.0.0"
VERSION = "5.0.0"
DESCRIPTION = " Remove your comment history on Reddit as deleting an account does not do so."
here = path.abspath(path.dirname(__file__))

@ -1,6 +1,7 @@
---
# Login details for Reddit. Fill out if you don't wish
# to be prompted for a login every time you run Shreddit.
# If your username or password has characters that could cause problems, surround them in quotes.
### NOTE: This may be deprecated as you can specify in praw.ini instead
username:
password:
@ -38,6 +39,15 @@ whitelist: [AskScience, TheCulture, redditdev, programming, charity, netsec]
# If you want any specific posts to be whitelisted stick 'em in here
whitelist_ids: []
# If you want to whitelist or blacklist specific multireddits, add them here
# Each one must be a list of 2 elements: username, multireddit
# Example:
# multi_blacklist:
# - [myusername, mymulti]
# - [someotheruser, theirmulti]
multi_blacklist: []
multi_whitelist: []
# If you set this then no editing or deleting will be done
# but the output from the program will be shown as an example
trial_run: False

@ -4,6 +4,8 @@ default_config = {"username": None,
"save_directory": "/tmp",
"whitelist": [],
"whitelist_ids": [],
"multi_blacklist": [],
"multi_whitelist": [],
"item": "overview",
"sort": "new",
"whitelist_distinguished": True,

@ -39,12 +39,29 @@ class Shredder(object):
self._limit = None
self._api_calls = []
# Add any multireddit subreddits to the whitelist
self._whitelist = set([s.lower() for s in self._whitelist])
for username, multiname in self._multi_whitelist:
multireddit = self._r.get_multireddit(username, multiname)
for subreddit in multireddit.subreddits:
self._whitelist.add(str(subreddit).lower())
# Add any multireddit subreddits to the blacklist
self._blacklist = set()
for username, multiname in self._multi_blacklist:
multireddit = self._r.get_multireddit(username, multiname)
for subreddit in multireddit.subreddits:
self._blacklist.add(str(subreddit).lower())
self._logger.info("Deleting ALL items before {}".format(self._nuke_cutoff))
self._logger.info("Deleting items not whitelisted until {}".format(self._recent_cutoff))
self._logger.info("Ignoring ALL items after {}".format(self._recent_cutoff))
self._logger.info("Targeting {} sorted by {}".format(self._item, self._sort))
if self._blacklist:
self._logger.info("Deleting ALL items from subreddits {}".format(", ".join(list(self._blacklist))))
if self._whitelist:
self._logger.info("Keeping items from subreddits {}".format(", ".join(self._whitelist)))
self._logger.info("Keeping items from subreddits {}".format(", ".join(list(self._whitelist))))
if self._keep_a_copy and self._save_directory:
self._logger.info("Saving deleted items to: {}".format(self._save_directory))
if self._trial_run:
@ -62,7 +79,7 @@ class Shredder(object):
self.shred()
def _connect(self, praw_ini, username, password):
self._r = praw.Reddit(user_agent="shreddit/4.4")
self._r = praw.Reddit(user_agent="shreddit/5.0")
if praw_ini:
# PRAW won't panic if the file is invalid, so check first
if not os.path.exists(praw_ini):
@ -89,7 +106,7 @@ class Shredder(object):
raise RateLimitExceeded("You're doing that too much.", e)
self._logger.info("Logged in as {user}.".format(user=self._r.user))
def _check_item(self, item):
def _check_whitelist(self, item):
"""Returns True if the item is whitelisted, False otherwise.
"""
if str(item.subreddit).lower() in self._whitelist or item.id in self._whitelist_ids:
@ -157,15 +174,18 @@ class Shredder(object):
time.sleep(10)
self._logger.debug("Examining item {}: {}".format(idx + 1, item))
created = arrow.get(item.created_utc)
if str(item.subreddit).lower() in self._blacklist:
self._logger.debug("Deleting due to blacklist")
self._remove(item)
elif self._check_whitelist(item):
self._logger.debug("Skipping due to: whitelisted")
continue
if created <= self._nuke_cutoff:
self._logger.debug("Item occurs prior to nuke cutoff")
self._remove(item)
elif created > self._recent_cutoff:
self._logger.debug("Skipping due to: too recent")
continue
elif self._check_item(item):
self._logger.debug("Skipping due to: whitelisted")
continue
else:
self._remove(item)
return idx + 1

@ -1,6 +1,7 @@
---
# Login details for Reddit. Fill out if you don't wish
# to be prompted for a login every time you run Shreddit.
# If your username or password has characters that could cause problems, surround them in quotes.
### NOTE: This may be deprecated as you can specify in praw.ini instead
username:
password:
@ -38,6 +39,15 @@ whitelist: [AskScience, TheCulture, redditdev, programming, charity, netsec]
# If you want any specific posts to be whitelisted stick 'em in here
whitelist_ids: []
# If you want to whitelist or blacklist specific multireddits, add them here
# Each one must be a list of 2 elements: username, multireddit
# Example:
# multi_blacklist:
# - [myusername, mymulti]
# - [someotheruser, theirmulti]
multi_blacklist: []
multi_whitelist: []
# If you set this then no editing or deleting will be done
# but the output from the program will be shown as an example
trial_run: False

Loading…
Cancel
Save