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
|
||||
import argparse
|
||||
import fcntl
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
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 overlay import format_age, format_location
|
||||
|
||||
# waveshare_epd is imported lazily after the lock — its epdconfig claims
|
||||
# GPIO pins at import time, so two overlapping invocations would both crash
|
||||
# on "GPIO busy" before reaching the flock below.
|
||||
# waveshare_epd is imported lazily only when a render will actually happen.
|
||||
# Its epdconfig claims GPIO pins at import time, so skip paths should not touch it.
|
||||
|
||||
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 = {"Andras": "person.andras", "Ruby": "person.ruby"}
|
||||
|
||||
def _parse_presence(spec: str) -> list[str]:
|
||||
"""Parse comma-separated Home Assistant entity IDs."""
|
||||
return [entity_id.strip() for entity_id in spec.split(",") if entity_id.strip()]
|
||||
|
||||
|
||||
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.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(
|
||||
|
|
@ -52,36 +59,40 @@ def main() -> None:
|
|||
print("Another instance running, skipping")
|
||||
sys.exit(0)
|
||||
|
||||
from waveshare_epd import epd7in3e
|
||||
|
||||
now = datetime.now()
|
||||
print(f"Time: {now.strftime('%H:%M')}")
|
||||
if now.hour < 7:
|
||||
print("Night time, skipping")
|
||||
sys.exit(0)
|
||||
|
||||
ha = HomeAssistantClient(HA_URL, HA_TOKEN)
|
||||
home = [name for name, eid in HA_PRESENCE.items() if ha.is_person_home(eid)]
|
||||
ha = HomeAssistantClient(ha_url, ha_token)
|
||||
home = [entity_id for entity_id in ha_presence if ha.is_person_home(entity_id)]
|
||||
if not home:
|
||||
print("No one home, skipping")
|
||||
sys.exit(0)
|
||||
print(f"Home: {', '.join(home)}")
|
||||
|
||||
client = ImmichClient(IMMICH_URL, IMMICH_API_KEY)
|
||||
client = ImmichClient(immich_url, immich_api_key)
|
||||
if args.album:
|
||||
image_path, asset = get_random_photo_from_album(client, args.album, args.orientation)
|
||||
print(f"Album: {args.album}")
|
||||
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)
|
||||
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)
|
||||
right_text = format_location(asset)
|
||||
if left_text or right_text:
|
||||
print(f"Overlay: {left_text or '-'} | {right_text or '-'}")
|
||||
|
||||
try:
|
||||
from waveshare_epd import epd7in3e
|
||||
|
||||
epd = epd7in3e.EPD()
|
||||
try:
|
||||
epd.init()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue