add optional user specification

This commit is contained in:
2026-03-04 05:56:04 +00:00
parent 2748a5a75b
commit 328de3c766
3 changed files with 29 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ try:
szuru_url = os.environ["SZURU_URL"]
szuru_user = os.environ["SZURU_USER"]
szuru_token = os.environ["SZURU_TOKEN"]
allowed_user = os.getenv("ALLOWED_USER")
except KeyError as e:
raise ValueError(f"Missing required environment variable: {e}")
@@ -41,8 +42,19 @@ while post is None and retries < MAX_RETRIES:
continue
if temp_post and temp_post.mime.startswith("image/") and temp_post.content:
# User info is in _json['user']['name']
post_user = temp_post._json.get("user", {}).get("name", "Unknown")
if allowed_user and post_user != allowed_user:
print(
f"[DEBUG] Skipping post ID: {random_id} - uploaded by {post_user}, but only {allowed_user} is allowed. (Retry {retries + 1}/{MAX_RETRIES})"
)
retries += 1
continue
post = temp_post
print(f"[DEBUG] Found image post with ID: {post.id_}, MIME: {post.mime}")
print(
f"[DEBUG] Found image post with ID: {post.id_}, MIME: {post.mime} (User: {post_user})"
)
else:
print(
f"[DEBUG] Skipping post ID: {random_id} (MIME: {temp_post.mime if temp_post else 'None'}, Content: {bool(temp_post.content) if temp_post else 'None'}) - not a valid image. (Retry {retries + 1}/{MAX_RETRIES})"
@@ -91,9 +103,17 @@ while not image_downloaded:
continue
if temp_post and temp_post.mime.startswith("image/") and temp_post.content:
post_user = temp_post._json.get("user", {}).get("name", "Unknown")
if allowed_user and post_user != allowed_user:
print(
f"[DEBUG] Skipping post ID: {random_id} - uploaded by {post_user}, but only {allowed_user} is allowed. (Retry {retries + 1}/{MAX_RETRIES})"
)
retries += 1
continue
post = temp_post
print(
f"[DEBUG] Found new image post with ID: {post.id_}, MIME: {post.mime}"
f"[DEBUG] Found new image post with ID: {post.id_}, MIME: {post.mime} (User: {post_user})"
)
else:
print(