handle missing posts

This commit is contained in:
2026-03-04 05:51:40 +00:00
parent 72bc286601
commit b5d6fc2152

View File

@@ -6,6 +6,7 @@ import random
import requests
import os
import pyszuru
from pyszuru.api import SzurubooruHTTPError
from PIL import Image, ImageSequence, UnidentifiedImageError
@@ -13,7 +14,6 @@ from epd.epd_config import palArr, epdArr, EPD_TYPES
from epd.image_processor import getErr, getNear, addVal, procImg
from epd.epd_uploader import upload_image
# get truly random post
try:
szuru_url = os.environ["SZURU_URL"]
@@ -28,7 +28,15 @@ highest_post = next(booru.search_post("sort:id type:image", page_size=1))
post = None
while post is None:
random_id = random.randint(0, highest_post.id_)
temp_post = booru.getPost(random_id)
try:
temp_post = booru.getPost(random_id)
except SzurubooruHTTPError:
print(
f"[DEBUG] Skipping post ID: {random_id} - Post not found. (Retry {retries + 1}/{MAX_RETRIES})"
)
retries += 1
continue
if temp_post and temp_post.mime.startswith("image/") and temp_post.content:
post = temp_post
print(f"[DEBUG] Found image post with ID: {post.id_}, MIME: {post.mime}")
@@ -66,7 +74,15 @@ while not image_downloaded:
post = None
while post is None:
random_id = random.randint(0, highest_post.id_)
temp_post = booru.getPost(random_id)
try:
temp_post = booru.getPost(random_id)
except SzurubooruHTTPError:
print(
f"[DEBUG] Skipping post ID: {random_id} - Post not found. (Retry {retries + 1}/{MAX_RETRIES})"
)
retries += 1
continue
if temp_post and temp_post.mime.startswith("image/") and temp_post.content:
post = temp_post
print(