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

Commit

Permalink
Hopefully fix 403 errors (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Jun 30, 2023
1 parent b1b196a commit d8244bc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 47 deletions.
68 changes: 34 additions & 34 deletions tor_archivist/core/queue_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,40 @@ def _auto_report_handling(cfg: Config, r_submission: Any, b_submission: Dict, re
"""
try:
partner_submission = cfg.reddit.submission(url=r_submission.url)

# Check if the post is marked as NSFW on the partner sub
if partner_submission.over_18:
if not r_submission.over_18:
nsfw_on_reddit(r_submission)
if not b_submission["nsfw"]:
nsfw_on_blossom(cfg, b_submission)

# Check if the post has been removed on the partner sub
if partner_submission.removed_by_category:
# Removed on the partner sub, it's safe to remove
# But only do it if the submission is not marked as removed already
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)
# We can ignore the report
return True

# Check if the post has been removed by a mod
if r_submission.removed_by_category:
if not b_submission["removed_from_reddit"]:
remove_on_blossom(cfg, b_submission)
# We can ignore the report
return True

if reason == NSFW_POST_REPORT_REASON:
# We already handled NSFW reports
# We still need to approve the submission to remove the item from mod queue
approve_on_reddit(r_submission)
approve_on_blossom(cfg, b_submission)
return True

return False
except Forbidden:
# The subreddit is private, remove the post from the queue
logging.warning(f"Removing submission from private sub: {b_submission['tor_url']}")
Expand All @@ -64,40 +98,6 @@ def _auto_report_handling(cfg: Config, r_submission: Any, b_submission: Dict, re
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:
if not r_submission.over_18:
nsfw_on_reddit(r_submission)
if not b_submission["nsfw"]:
nsfw_on_blossom(cfg, b_submission)

# Check if the post has been removed on the partner sub
if partner_submission.removed_by_category:
# Removed on the partner sub, it's safe to remove
# But only do it if the submission is not marked as removed already
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)
# We can ignore the report
return True

# Check if the post has been removed by a mod
if r_submission.removed_by_category:
if not b_submission["removed_from_reddit"]:
remove_on_blossom(cfg, b_submission)
# We can ignore the report
return True

if reason == NSFW_POST_REPORT_REASON:
# We already handled NSFW reports
# We still need to approve the submission to remove the item from mod queue
approve_on_reddit(r_submission)
approve_on_blossom(cfg, b_submission)
return True

return False


def track_post_removal(cfg: Config) -> None:
"""Process the mod log and sync post removals to Blossom."""
Expand Down
25 changes: 12 additions & 13 deletions tor_archivist/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ def process_expired_posts(cfg: Config) -> None:
# We need to update the Blossom object to remove this post from the endpoint
try:
partner_submission = cfg.reddit.submission(url=r_submission.url)

# Update NSFW status just to be safe
if not r_submission.over_18 and partner_submission.over_18:
nsfw_on_reddit(r_submission)
nsfw_on_blossom(cfg, b_submission)

if partner_submission.removed_by_category:
# The submission has been removed on the partner sub, remove it on Blossom
remove_on_blossom(cfg, b_submission)
else:
# Archive it on Blossom
cfg.blossom.archive_submission(submission_id=b_submission["id"])
except Forbidden:
# The sub is private, remove the submission from the queue
logging.warning(
Expand All @@ -89,19 +101,6 @@ def process_expired_posts(cfg: Config) -> None:
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:
nsfw_on_reddit(r_submission)
nsfw_on_blossom(cfg, b_submission)

if partner_submission.removed_by_category:
# The submission has been removed on the partner sub, remove it on Blossom
remove_on_blossom(cfg, b_submission)
else:
# Archive it on Blossom
cfg.blossom.archive_submission(submission_id=b_submission["id"])


def get_human_transcription(cfg: Config, submission: Dict) -> Dict:
Expand Down

0 comments on commit d8244bc

Please sign in to comment.