diff --git a/README.md b/README.md index a87edd5..00a71c8 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,8 @@ display. **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 -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, if provided) before giving up. diff --git a/docker-compose.yml b/docker-compose.yml index d6cf386..04b615a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,9 +5,10 @@ services: build: . container_name: szuru-eink-bot 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_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 diff --git a/szuru-eink.py b/szuru-eink.py index cbed386..b9f4271 100644 --- a/szuru-eink.py +++ b/szuru-eink.py @@ -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(