Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/auto-push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ jobs:
python-version: '3.x'

- name: Install dependencies
run: |
pip install ruff
pip install -r tests/requirements.txt
run: pip install -e ".[dev]"

- name: Lint (ruff)
run: ruff check .
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/backfill-drive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
python-version: '3.x'

- name: Install dependencies
run: pip install -r requirements.txt
run: pip install -e ".[drive]"

- name: Upload historical artifacts to Google Drive
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
with:
python-version: '3.x'

- name: Install test dependencies
run: pip install -r tests/requirements.txt
- name: Install dependencies
run: pip install -e ".[dev]"

- name: Run tests
run: pytest tests/ -v
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
with:
python-version: "3.x"
- name: Install dependencies
run: pip install -r tests/requirements.txt
run: pip install -e ".[dev]"
- name: Run tests
run: pytest
run: pytest tests/ -v
4 changes: 2 additions & 2 deletions .github/workflows/weekly-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
python-version: '3.x'

- name: Install dependencies
run: pip install -r requirements.txt
run: pip install -e ".[drive]"

- name: Run weekly cleanup (score < 1, or score == 1 and older than 14 days)
env:
Expand All @@ -32,7 +32,7 @@ jobs:
# Optional — omit these two secrets to skip Drive upload
GOOGLE_SERVICE_ACCOUNT_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}
GOOGLE_DRIVE_FOLDER_ID: ${{ secrets.GOOGLE_DRIVE_FOLDER_ID }}
run: python weekly_cleanup.py
run: python -m redditcleaner.ci.weekly_cleanup

- name: Upload deletion logs as artifacts
if: always()
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ __pycache__/
# Flask session / instance folder
instance/
flask_session/
src/redditcleaner.egg-info/
46 changes: 46 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"

[project]
name = "redditcleaner"
version = "1.8.0"
requires-python = ">=3.9"
dependencies = [
"praw>=7.6,<8",
]

[project.optional-dependencies]
drive = [
"google-api-python-client>=2.0,<3",
"google-auth>=2.0,<3",
"google-auth-httplib2>=0.1,<1",
]
web = [
"flask>=2.3,<4",
"flask-wtf>=1.1,<2",
"google-api-python-client>=2.0,<3",
"google-auth>=2.0,<3",
"google-auth-httplib2>=0.1,<1",
]
dev = [
"pytest>=7.0,<9",
"pytest-mock>=3.0,<4",
"flask>=2.3,<4",
"flask-wtf>=1.1,<2",
"ruff",
]

[project.scripts]
reddit-clean-comments = "redditcleaner.cli.comment_cleaner:main"
reddit-clean-posts = "redditcleaner.cli.post_cleaner:main"
reddit-weekly-cleanup = "redditcleaner.ci.weekly_cleanup:main"

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
"redditcleaner.web" = ["templates/*.html"]

[tool.pytest.ini_options]
testpaths = ["tests"]
3 changes: 0 additions & 3 deletions pytest.ini

This file was deleted.

4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

7 changes: 1 addition & 6 deletions scripts/backfill_drive_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@
import tempfile
import zipfile

# Allow importing drive_upload from the repo root when run from any directory.
_REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if _REPO_ROOT not in sys.path:
sys.path.insert(0, _REPO_ROOT)

from drive_upload import upload_logs # noqa: E402
from redditcleaner.drive_upload import upload_logs


def _gh_api(path: str) -> dict:
Expand Down
3 changes: 3 additions & 0 deletions src/redditcleaner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""RedditCommentCleaner — bulk-delete Reddit comments and posts."""

__version__ = "1.8.0"
Empty file.
29 changes: 6 additions & 23 deletions weekly_cleanup.py → src/redditcleaner/ci/weekly_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Credential resolution order:
1. Environment variables (REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET,
REDDIT_USERNAME, REDDIT_PASSWORD)
2. Credentials.txt in the same directory (four lines: client_id,
2. Credentials.txt in the current working directory (four lines: client_id,
client_secret, username, password)

Optional environment variables:
Expand All @@ -17,37 +17,20 @@
DRY_RUN set to "1" to preview deletions without making changes

Usage:
python weekly_cleanup.py # normal run
python weekly_cleanup.py --dry-run # preview only, nothing deleted
python -m redditcleaner.ci.weekly_cleanup # normal run
python -m redditcleaner.ci.weekly_cleanup --dry-run # preview only, nothing deleted
"""

import argparse
import json
import os
import time
from datetime import datetime, timezone

import praw
import prawcore

from drive_upload import maybe_upload_logs

_RETRY_WAIT = (5, 15, 45)


def _with_retry(fn, label="operation"):
"""Call fn(), retrying up to 3 times on rate-limit errors."""
for attempt, wait in enumerate(_RETRY_WAIT, start=1):
try:
return fn()
except prawcore.exceptions.TooManyRequests as exc:
retry_after = getattr(exc, "retry_after", None) or wait
print(f" Rate limited on {label}. Waiting {retry_after}s (attempt {attempt}/3)…")
time.sleep(retry_after)
except praw.exceptions.APIException:
raise
return fn()

from redditcleaner.drive_upload import maybe_upload_logs
from redditcleaner.utils import _with_retry

AGE_THRESHOLD_DAYS = 14

Expand All @@ -65,7 +48,7 @@ def _load_credentials():
if all([client_id, client_secret, username, password]):
return client_id, client_secret, username, password

cred_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Credentials.txt")
cred_path = os.path.join(os.getcwd(), "Credentials.txt")
if os.path.exists(cred_path):
with open(cred_path, encoding="utf-8") as f:
lines = [line.strip() for line in f.readlines()]
Expand Down
Empty file.
Loading
Loading