Print immich url
This commit is contained in:
parent
a7cd888778
commit
5890237449
1 changed files with 27 additions and 16 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import argparse
|
import argparse
|
||||||
import fcntl
|
import fcntl
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -14,22 +15,28 @@ from homeassistant import HomeAssistantClient
|
||||||
from immich import ImmichClient, get_random_photo_from_album, get_random_photo_of_people
|
from immich import ImmichClient, get_random_photo_from_album, get_random_photo_of_people
|
||||||
from overlay import format_age, format_location
|
from overlay import format_age, format_location
|
||||||
|
|
||||||
# waveshare_epd is imported lazily after the lock — its epdconfig claims
|
# waveshare_epd is imported lazily only when a render will actually happen.
|
||||||
# GPIO pins at import time, so two overlapping invocations would both crash
|
# Its epdconfig claims GPIO pins at import time, so skip paths should not touch it.
|
||||||
# on "GPIO busy" before reaching the flock below.
|
|
||||||
|
|
||||||
load_env()
|
|
||||||
IMMICH_URL = require("IMMICH_URL")
|
def _parse_presence(spec: str) -> list[str]:
|
||||||
IMMICH_API_KEY = require("IMMICH_API_KEY")
|
"""Parse comma-separated Home Assistant entity IDs."""
|
||||||
HA_URL = require("HA_URL")
|
return [entity_id.strip() for entity_id in spec.split(",") if entity_id.strip()]
|
||||||
HA_TOKEN = require("HA_TOKEN")
|
|
||||||
HA_PRESENCE = {"Andras": "person.andras", "Ruby": "person.ruby"}
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
load_env()
|
||||||
|
immich_url = require("IMMICH_URL")
|
||||||
|
immich_api_key = require("IMMICH_API_KEY")
|
||||||
|
ha_url = require("HA_URL")
|
||||||
|
ha_token = require("HA_TOKEN")
|
||||||
|
ha_presence = _parse_presence(require("HA_PRESENCE"))
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Display image on e-ink frame")
|
parser = argparse.ArgumentParser(description="Display image on e-ink frame")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--people", default="Me,Ruby", help="Comma-separated names for Immich search"
|
"--people",
|
||||||
|
default=os.environ.get("IMMICH_PEOPLE", ""),
|
||||||
|
help="Comma-separated names for Immich search (default from IMMICH_PEOPLE env var)",
|
||||||
)
|
)
|
||||||
parser.add_argument("--album", help="Fetch from album (overrides --people)")
|
parser.add_argument("--album", help="Fetch from album (overrides --people)")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
@ -52,36 +59,40 @@ def main() -> None:
|
||||||
print("Another instance running, skipping")
|
print("Another instance running, skipping")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
from waveshare_epd import epd7in3e
|
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
print(f"Time: {now.strftime('%H:%M')}")
|
print(f"Time: {now.strftime('%H:%M')}")
|
||||||
if now.hour < 7:
|
if now.hour < 7:
|
||||||
print("Night time, skipping")
|
print("Night time, skipping")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
ha = HomeAssistantClient(HA_URL, HA_TOKEN)
|
ha = HomeAssistantClient(ha_url, ha_token)
|
||||||
home = [name for name, eid in HA_PRESENCE.items() if ha.is_person_home(eid)]
|
home = [entity_id for entity_id in ha_presence if ha.is_person_home(entity_id)]
|
||||||
if not home:
|
if not home:
|
||||||
print("No one home, skipping")
|
print("No one home, skipping")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
print(f"Home: {', '.join(home)}")
|
print(f"Home: {', '.join(home)}")
|
||||||
|
|
||||||
client = ImmichClient(IMMICH_URL, IMMICH_API_KEY)
|
client = ImmichClient(immich_url, immich_api_key)
|
||||||
if args.album:
|
if args.album:
|
||||||
image_path, asset = get_random_photo_from_album(client, args.album, args.orientation)
|
image_path, asset = get_random_photo_from_album(client, args.album, args.orientation)
|
||||||
print(f"Album: {args.album}")
|
print(f"Album: {args.album}")
|
||||||
else:
|
else:
|
||||||
names = [n.strip() for n in args.people.split(",")]
|
names = [n.strip() for n in args.people.split(",") if n.strip()]
|
||||||
|
if not names:
|
||||||
|
sys.exit("Specify --people or --album, or set IMMICH_PEOPLE in .env")
|
||||||
image_path, asset = get_random_photo_of_people(client, names, args.orientation)
|
image_path, asset = get_random_photo_of_people(client, names, args.orientation)
|
||||||
print(f"People: {', '.join(names)}")
|
print(f"People: {', '.join(names)}")
|
||||||
|
|
||||||
|
asset_id = asset.get("id")
|
||||||
|
print(f"Immich image: {client.base_url}/photos/{asset_id}")
|
||||||
left_text = format_age(asset)
|
left_text = format_age(asset)
|
||||||
right_text = format_location(asset)
|
right_text = format_location(asset)
|
||||||
if left_text or right_text:
|
if left_text or right_text:
|
||||||
print(f"Overlay: {left_text or '-'} | {right_text or '-'}")
|
print(f"Overlay: {left_text or '-'} | {right_text or '-'}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
from waveshare_epd import epd7in3e
|
||||||
|
|
||||||
epd = epd7in3e.EPD()
|
epd = epd7in3e.EPD()
|
||||||
try:
|
try:
|
||||||
epd.init()
|
epd.init()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue