Compare commits
1 Commits
master
...
7699bdd305
| Author | SHA1 | Date | |
|---|---|---|---|
| 7699bdd305 |
@@ -1,2 +1,2 @@
|
|||||||
python 3.14.3
|
python 3.13.0
|
||||||
nodejs 25.8.0
|
nodejs 24.4.1
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.14.3-alpine
|
FROM python:3.11.5-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN pip install uv
|
RUN pip install uv
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ screen](https://gitea.bubbletea.dev/shibao/szuru-eink-bot/raw/branch/master/eink
|
|||||||
- Fetches random images from a configurable Szurubooru instance.
|
- Fetches random images from a configurable Szurubooru instance.
|
||||||
- Resizes and dithered images for e-ink display compatibility.
|
- Resizes and dithered images for e-ink display compatibility.
|
||||||
- Supports monochrome and color dithering (for compatible displays).
|
- Supports monochrome and color dithering (for compatible displays).
|
||||||
- Filters images by an optional allowed username.
|
|
||||||
- Uploads processed images to a Waveshare e-ink screen.
|
- Uploads processed images to a Waveshare e-ink screen.
|
||||||
- Configurable via environment variables.
|
- Configurable via environment variables.
|
||||||
- Designed to run as a Docker container on a cron job.
|
- Designed to run as a Docker container on a cron job.
|
||||||
@@ -42,10 +41,7 @@ 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`. `ALLOWED_USER` is optional;
|
displays, ensure `DITHERING_MODE` is set to `color`.
|
||||||
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.
|
|
||||||
|
|
||||||
### 3. Build and Run with Docker Compose
|
### 3. Build and Run with Docker Compose
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ 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
|
||||||
|
|||||||
@@ -2,18 +2,14 @@
|
|||||||
name = "szuru-eink"
|
name = "szuru-eink"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = ""
|
description = ""
|
||||||
authors = [
|
authors = []
|
||||||
{ name = "shibao" },
|
requires-python = "==3.13.5"
|
||||||
]
|
|
||||||
requires-python = ">=3.14"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aioipfs==0.7.1",
|
"aioipfs==0.6.5",
|
||||||
"pyszuru==0.4.0",
|
"pyszuru==0.3.1",
|
||||||
"requests==2.32.5",
|
"Requests==2.31.0",
|
||||||
"pillow==12.1.1",
|
"Pillow==11.3.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
dev = [
|
dev = ["black==24.4.2"]
|
||||||
"black==26.1.0",
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import random
|
|||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
import pyszuru
|
import pyszuru
|
||||||
from pyszuru.api import SzurubooruHTTPError
|
|
||||||
from PIL import Image, ImageSequence, UnidentifiedImageError
|
from PIL import Image, ImageSequence, UnidentifiedImageError
|
||||||
|
|
||||||
|
|
||||||
@@ -14,12 +13,12 @@ from epd.epd_config import palArr, epdArr, EPD_TYPES
|
|||||||
from epd.image_processor import getErr, getNear, addVal, procImg
|
from epd.image_processor import getErr, getNear, addVal, procImg
|
||||||
from epd.epd_uploader import upload_image
|
from epd.epd_uploader import upload_image
|
||||||
|
|
||||||
|
|
||||||
# get truly random post
|
# get truly random post
|
||||||
try:
|
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}")
|
||||||
|
|
||||||
@@ -27,42 +26,16 @@ booru = pyszuru.API(szuru_url, username=szuru_user, token=szuru_token)
|
|||||||
highest_post = next(booru.search_post("sort:id type:image", page_size=1))
|
highest_post = next(booru.search_post("sort:id type:image", page_size=1))
|
||||||
|
|
||||||
post = None
|
post = None
|
||||||
retries = 0
|
while post is None:
|
||||||
MAX_RETRIES = 100
|
random_id = 10455 # For testing, always use ID=10455 which is a gif
|
||||||
|
temp_post = booru.getPost(random_id)
|
||||||
while post is None and retries < MAX_RETRIES:
|
|
||||||
random_id = random.randint(0, highest_post.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:
|
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(
|
print(f"[DEBUG] Found image post with ID: {post.id_}, MIME: {post.mime}")
|
||||||
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."
|
||||||
)
|
)
|
||||||
retries += 1
|
|
||||||
|
|
||||||
if post is None:
|
|
||||||
raise RuntimeError(f"Failed to find a valid post after {MAX_RETRIES} retries.")
|
|
||||||
|
|
||||||
# download image
|
# download image
|
||||||
image_downloaded = False
|
image_downloaded = False
|
||||||
@@ -91,40 +64,18 @@ while not image_downloaded:
|
|||||||
os.remove("image.jpg")
|
os.remove("image.jpg")
|
||||||
# Find a new post
|
# Find a new post
|
||||||
post = None
|
post = None
|
||||||
while post is None and retries < MAX_RETRIES:
|
while post is None:
|
||||||
random_id = random.randint(0, highest_post.id_)
|
random_id = 10455 # For testing, always use ID=10455 which is a gif
|
||||||
try:
|
temp_post = booru.getPost(random_id)
|
||||||
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:
|
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} (User: {post_user})"
|
f"[DEBUG] Found new image post with ID: {post.id_}, MIME: {post.mime}"
|
||||||
)
|
)
|
||||||
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."
|
||||||
)
|
)
|
||||||
retries += 1
|
|
||||||
|
|
||||||
if post is None:
|
|
||||||
raise RuntimeError(
|
|
||||||
f"Failed to find a valid post after {MAX_RETRIES} retries."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Process and upload
|
# Process and upload
|
||||||
img = Image.open("image.jpg")
|
img = Image.open("image.jpg")
|
||||||
|
|||||||
Reference in New Issue
Block a user