add optional user specification
This commit is contained in:
@@ -42,7 +42,8 @@ display.
|
|||||||
|
|
||||||
**Note:** For `EPD_TYPE`, refer to the `epd/epd_config.py` file for a full list
|
**Note:** For `EPD_TYPE`, refer to the `epd/epd_config.py` file for a full list
|
||||||
of supported display types and their corresponding string labels. For color
|
of supported display types and their corresponding string labels. For color
|
||||||
displays, ensure `DITHERING_MODE` is set to `color`. The bot
|
displays, ensure `DITHERING_MODE` is set to `color`. `ALLOWED_USER` is optional;
|
||||||
|
if set, the bot will only fetch images uploaded by that specific user. The bot
|
||||||
will retry a maximum of 100 times to find a valid image (matching the user filter,
|
will retry a maximum of 100 times to find a valid image (matching the user filter,
|
||||||
if provided) before giving up.
|
if provided) before giving up.
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
container_name: szuru-eink-bot
|
container_name: szuru-eink-bot
|
||||||
environment:
|
environment:
|
||||||
|
- ALLOWED_USER=YOUR_ALLOWED_USER # optional: only fetch images from this user
|
||||||
|
- DITHERING_MODE=YOUR_DITHERING_MODE # e.g., mono, color
|
||||||
|
- EINK_IP=YOUR_EINK_IP
|
||||||
|
- EPD_TYPE=YOUR_EPD_TYPE # e.g., '7.5 V2', 5.65f
|
||||||
|
- SZURU_TOKEN=YOUR_SZURU_TOKEN
|
||||||
- SZURU_URL=YOUR_SZURU_URL
|
- SZURU_URL=YOUR_SZURU_URL
|
||||||
- SZURU_USER=YOUR_SZURU_USER
|
- SZURU_USER=YOUR_SZURU_USER
|
||||||
- SZURU_TOKEN=YOUR_SZURU_TOKEN
|
|
||||||
- EPD_TYPE=YOUR_EPD_TYPE # e.g., '7.5 V2', 5.65f
|
|
||||||
- EINK_IP=YOUR_EINK_IP
|
|
||||||
- DITHERING_MODE=YOUR_DITHERING_MODE # e.g., mono, color
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ try:
|
|||||||
szuru_url = os.environ["SZURU_URL"]
|
szuru_url = os.environ["SZURU_URL"]
|
||||||
szuru_user = os.environ["SZURU_USER"]
|
szuru_user = os.environ["SZURU_USER"]
|
||||||
szuru_token = os.environ["SZURU_TOKEN"]
|
szuru_token = os.environ["SZURU_TOKEN"]
|
||||||
|
allowed_user = os.getenv("ALLOWED_USER")
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
raise ValueError(f"Missing required environment variable: {e}")
|
raise ValueError(f"Missing required environment variable: {e}")
|
||||||
|
|
||||||
@@ -41,8 +42,19 @@ while post is None and retries < MAX_RETRIES:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if temp_post and temp_post.mime.startswith("image/") and temp_post.content:
|
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
|
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:
|
else:
|
||||||
print(
|
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})"
|
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
|
continue
|
||||||
|
|
||||||
if temp_post and temp_post.mime.startswith("image/") and temp_post.content:
|
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
|
post = temp_post
|
||||||
print(
|
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:
|
else:
|
||||||
print(
|
print(
|
||||||
|
|||||||
Reference in New Issue
Block a user