-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated for stability #180
Open
kayla-tokash
wants to merge
18
commits into
x89:master
Choose a base branch
from
kayla-tokash:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c28fd4b
Cleaned up merge that was improper
99c9bbc
Fixes for stability
5e63f14
Fixes for stability
0c283bf
Fixes for stability
8c10fcb
Fixing generator
0f51175
Fixes for stability
a495506
Update README.md
kayla-tokash 07937a9
Update README.md
kayla-tokash 5159cc0
Update README.md
kayla-tokash 834bca3
Update README.md
kayla-tokash a109ebd
Update README.md
kayla-tokash b72b170
Update README.md
kayla-tokash e60c26f
Update README.md
kayla-tokash 5e1f7d1
Update README.md
kayla-tokash 6b7d061
Update README.md
kayla-tokash ccff7aa
Update shreddit/shredder.py
kayla-tokash 21495b0
Update shreddit/shredder.py
kayla-tokash ae1a135
Update shreddit/shredder.py
kayla-tokash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,12 +18,14 @@ class Shredder(object): | |||||||||||||
"""This class stores state for configuration, API objects, logging, etc. It exposes a shred() method that | ||||||||||||||
application code can call to start it. | ||||||||||||||
""" | ||||||||||||||
_batch_size=1000 | ||||||||||||||
|
||||||||||||||
def __init__(self, config, user): | ||||||||||||||
logging.basicConfig() | ||||||||||||||
self._logger = logging.getLogger("shreddit") | ||||||||||||||
self._logger.setLevel(level=logging.DEBUG if config.get("verbose", True) else logging.INFO) | ||||||||||||||
self.__dict__.update({"_{}".format(k): config[k] for k in config}) | ||||||||||||||
|
||||||||||||||
self._batch_size = config.get("batch_size", 1000) | ||||||||||||||
self._user = user | ||||||||||||||
self._connect() | ||||||||||||||
|
||||||||||||||
|
@@ -67,7 +69,7 @@ def __init__(self, config, user): | |||||||||||||
def shred(self): | ||||||||||||||
deleted = self._remove_things(self._build_iterator()) | ||||||||||||||
self._logger.info("Finished deleting {} items. ".format(deleted)) | ||||||||||||||
if deleted >= 1000: | ||||||||||||||
if deleted >= self._batch_size: | ||||||||||||||
# This user has more than 1000 items to handle, which angers the gods of the Reddit API. So chill for a | ||||||||||||||
# while and do it again. | ||||||||||||||
self._logger.info("Waiting {} seconds and continuing...".format(self._batch_cooldown)) | ||||||||||||||
|
@@ -128,20 +130,28 @@ def _remove_comment(self, comment): | |||||||||||||
comment.edit(replacement_text) | ||||||||||||||
|
||||||||||||||
def _remove(self, item): | ||||||||||||||
if self._keep_a_copy and self._save_directory: | ||||||||||||||
self._save_item(item) | ||||||||||||||
if not self._trial_run: | ||||||||||||||
if self._clear_vote: | ||||||||||||||
try: | ||||||||||||||
item.clear_vote() | ||||||||||||||
except BadRequest: | ||||||||||||||
self._logger.debug("Couldn't clear vote on {item}".format(item=item)) | ||||||||||||||
if isinstance(item, Submission): | ||||||||||||||
self._remove_submission(item) | ||||||||||||||
elif isinstance(item, Comment): | ||||||||||||||
self._remove_comment(item) | ||||||||||||||
if not self._trial_run: | ||||||||||||||
item.delete() | ||||||||||||||
while 1: | ||||||||||||||
try: | ||||||||||||||
if self._keep_a_copy and self._save_directory: | ||||||||||||||
self._save_item(item) | ||||||||||||||
if not self._trial_run: | ||||||||||||||
if self._clear_vote: | ||||||||||||||
try: | ||||||||||||||
item.clear_vote() | ||||||||||||||
except BadRequest: | ||||||||||||||
self._logger.debug("Couldn't clear vote on {item}".format(item=item)) | ||||||||||||||
kayla-tokash marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
if isinstance(item, Submission): | ||||||||||||||
self._remove_submission(item) | ||||||||||||||
elif isinstance(item, Comment): | ||||||||||||||
self._remove_comment(item) | ||||||||||||||
if not self._trial_run: | ||||||||||||||
item.delete() | ||||||||||||||
break | ||||||||||||||
except Exception as e: | ||||||||||||||
kayla-tokash marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
self._logger.debug("Encountered a problem with the API, probably ratelimiting thanks to bad admins") | ||||||||||||||
kayla-tokash marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
self._logger.error(f"Exception: {e}") | ||||||||||||||
self._logger.info(f"Waiting {self._batch_cooldown} seconds") | ||||||||||||||
time.sleep(self._batch_cooldown) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
def _remove_things(self, items): | ||||||||||||||
self._logger.info("Loading items to delete...") | ||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering how long the script takes to run, limiting max retries is not ideal. Add an option to run indefinitely if you're really trying to change it. I understand the distaste for
while 1
but the real experience is that it will not run to completion if you have a lot of posts because of the rate limiting.