Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
Handle private subreddits (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch authored Jun 30, 2023
1 parent 08384ec commit b1b196a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
13 changes: 12 additions & 1 deletion tor_archivist/core/queue_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, Optional

from prawcore import Forbidden

from tor_archivist.core.blossom import (
approve_on_blossom,
get_blossom_submission,
Expand Down Expand Up @@ -51,7 +53,16 @@ def _auto_report_handling(cfg: Config, r_submission: Any, b_submission: Dict, re
:returns: True if the report has been handled automatically, else False.
"""
partner_submission = cfg.reddit.submission(url=r_submission.url)
try:
partner_submission = cfg.reddit.submission(url=r_submission.url)
except Forbidden:
# The subreddit is private, remove the post from the queue
logging.warning(f"Removing submission from private sub: {b_submission['tor_url']}")
if not r_submission.removed_by_category:
remove_on_reddit(r_submission)
if not b_submission["removed_from_queue"]:
remove_on_blossom(cfg, b_submission)
return True

# Check if the post is marked as NSFW on the partner sub
if partner_submission.over_18:
Expand Down
16 changes: 14 additions & 2 deletions tor_archivist/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from blossom_wrapper import BlossomStatus
from click.core import Context
from dotenv import load_dotenv
from prawcore import Forbidden
from shiv.bootstrap import current_zipfile

from tor_archivist import (
Expand All @@ -32,7 +33,7 @@
track_post_removal,
track_post_reports,
)
from tor_archivist.core.reddit import nsfw_on_reddit
from tor_archivist.core.reddit import nsfw_on_reddit, remove_on_reddit

with current_zipfile() as archive:
if archive:
Expand Down Expand Up @@ -77,7 +78,18 @@ def process_expired_posts(cfg: Config) -> None:
)
# The post was not archived, but has been removed from ToR already
# We need to update the Blossom object to remove this post from the endpoint
partner_submission = cfg.reddit.submission(url=r_submission.url)
try:
partner_submission = cfg.reddit.submission(url=r_submission.url)
except Forbidden:
# The sub is private, remove the submission from the queue
logging.warning(
f"Removing submission from private sub: {b_submission['tor_url']}"
)
if not r_submission.removed_by_category:
remove_on_reddit(r_submission)
if not b_submission["removed_from_queue"]:
remove_on_blossom(cfg, b_submission)
return

# Update NSFW status just to be safe
if not r_submission.over_18 and partner_submission.over_18:
Expand Down

0 comments on commit b1b196a

Please sign in to comment.