Implement all improvements: utils, dry-run, CSRF, datetime, docs#37
Merged
Implement all improvements: utils, dry-run, CSRF, datetime, docs#37
Conversation
Shared utilities (utils.py) - Extract _with_retry, get_reddit_credentials, confirm_and_run, initialize_reddit, and get_days_old into utils.py so both CLI scripts and the web app import a single, maintained copy - Fix initialize_reddit to catch prawcore.exceptions.OAuthException and ResponseException in addition to praw.exceptions.APIException so bad-credential errors are always handled cleanly CLI scripts (commentCleaner.py, PostCleaner.py) - Add --dry-run flag (argparse) to preview deletions without changes - Add per-item progress counter (\r Scanning… N items fetched) - Open the log file once per function call instead of once per deletion - Replace deprecated datetime.utcnow() / utcfromtimestamp() with timezone-aware datetime.now(timezone.utc) / fromtimestamp(..., tz=utc) - Mode 1 (delete_old_comments): add past_cutoff flag to skip the age check for every item once the sorted stream crosses the threshold - Wrap edit/delete calls with _with_retry for rate-limit resilience - Add prawcore.exceptions.TooManyRequests to exception handlers Web app (web/app.py, index.html, dashboard.html) - Add CSRF protection via flask-wtf CSRFProtect; login form includes hidden csrf_token field; dashboard fetch sends X-CSRFToken header read from <meta name="csrf-token"> tag - Fix debug=True hardcoded; now reads FLASK_DEBUG env var - Replace bare except Exception with specific PRAW/prawcore exceptions in /login and /api/delete to avoid masking unexpected errors - Import _with_retry from utils; wrap all edit/delete calls - Open comment and post log files once per /api/delete request - All datetime calls now timezone-aware (timezone.utc) Requirements - Pin version ranges in requirements.txt, web/requirements.txt, and tests/requirements.txt (e.g. praw>=7.6,<8, flask>=2.3,<4) - Add flask-wtf>=1.1,<2 to web/requirements.txt Documentation (CLAUDE.md, README.md, SECURITY.md) - CLAUDE.md: add utils.py, android/, scripts/ to structure table; add sections for each; correct "No test suite" → "Test suite: tests/"; document --dry-run, FLASK_DEBUG, CSRF architecture, timezone convention - README.md: add Android app section with quick-start; add backfill script section; add --dry-run note to CLI section; update output-file format description to reflect JSON-lines format - SECURITY.md: update supported versions table to v1.8; expand reporting guidance; describe attack surface for each component https://claude.ai/code/session_014HLhrFtCVRFnEyfRexiy3d
Both sides added _with_retry / helper functions to the three conflicting
files; our branch extracts them to utils.py (single source of truth)
while main added them inline. Conflicts resolved by keeping our
version in all three files:
- commentCleaner.py: keep utils imports, timezone-aware datetimes,
dry-run, progress counter, past_cutoff optimisation, print("\n …")
with newline prefix on error messages
- PostCleaner.py: same approach — utils imports, dry-run, progress,
newline-prefixed messages, no inline _RETRY_WAIT / _with_retry
- web/app.py: keep `from datetime import datetime, timezone`,
utils import for _with_retry, log-once-per-request pattern,
specific PRAW exception handlers (not bare Exception)
weekly_cleanup.py auto-merged cleanly from main (no conflict).
https://claude.ai/code/session_014HLhrFtCVRFnEyfRexiy3d
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Shared utilities (utils.py)
CLI scripts (commentCleaner.py, PostCleaner.py)
Web app (web/app.py, index.html, dashboard.html)
Requirements
Documentation (CLAUDE.md, README.md, SECURITY.md)
https://claude.ai/code/session_014HLhrFtCVRFnEyfRexiy3d