diff --git a/.gitignore b/.gitignore index 75d8d78..e2dcc88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .venv __pycache__ .env +.agents +.codex \ No newline at end of file diff --git a/src/main.py b/src/main.py index 2e577d4..e246ef9 100644 --- a/src/main.py +++ b/src/main.py @@ -32,9 +32,7 @@ ALBUM_MODE = os.environ.get("ALBUM_MODE", "root").lower() ALBUM_SEPARATOR = os.environ.get("ALBUM_SEPARATOR", " - ") PAGE_SIZE = int(os.environ.get("PAGE_SIZE", "1000")) DRY_RUN = os.environ.get("DRY_RUN", "false").lower() == "true" -SYNC_INTERVAL_SECONDS = int( - os.environ.get("SYNC_INTERVAL_SECONDS", "1800") -) +SYNC_INTERVAL_SECONDS = int(os.environ.get("SYNC_INTERVAL_SECONDS", "1800")) logging.basicConfig( level=logging.INFO, @@ -65,22 +63,17 @@ def check_configuration() -> None: if missing: raise RuntimeError( - "The following environment variables are missing: " - + ", ".join(missing) + "The following environment variables are missing: " + ", ".join(missing) ) if ALBUM_MODE not in {"root", "leaf", "relative"}: - raise RuntimeError( - "ALBUM_MODE must be root, leaf, or relative" - ) + raise RuntimeError("ALBUM_MODE must be root, leaf, or relative") if not EXTERNAL_ROOT.startswith("/"): raise RuntimeError("EXTERNAL_ROOT must be an absolute path") if SYNC_INTERVAL_SECONDS < 0: - raise RuntimeError( - "SYNC_INTERVAL_SECONDS must be zero or greater" - ) + raise RuntimeError("SYNC_INTERVAL_SECONDS must be zero or greater") def api_request( @@ -100,8 +93,7 @@ def api_request( if not response.ok: raise RuntimeError( - f"{method} {url} failed: " - f"{response.status_code} {response.text}" + f"{method} {url} failed: {response.status_code} {response.text}" ) if response.status_code == 204 or not response.content: @@ -113,10 +105,7 @@ def api_request( def get_albums() -> dict[str, dict[str, Any]]: albums = api_request("GET", "/albums?isOwned=true") - return { - album["albumName"]: album - for album in albums - } + return {album["albumName"]: album for album in albums} def create_album(album_name: str) -> dict[str, Any]: @@ -171,11 +160,7 @@ def search_assets(**filters: Any) -> list[dict[str, Any]]: def get_album_asset_ids(album_id: str) -> set[str]: assets = search_assets(albumIds=[album_id]) - return { - asset["id"] - for asset in assets - if asset.get("id") - } + return {asset["id"] for asset in assets if asset.get("id")} def add_assets_to_album( @@ -281,9 +266,7 @@ def synchronize() -> None: # Immich v3 album responses no longer contain the asset list. existing_asset_ids = get_album_asset_ids(album_id) - missing_asset_ids = sorted( - set(desired_asset_ids) - existing_asset_ids - ) + missing_asset_ids = sorted(set(desired_asset_ids) - existing_asset_ids) if missing_asset_ids: logging.info( @@ -310,9 +293,7 @@ def main() -> int: except Exception: if SYNC_INTERVAL_SECONDS == 0: raise - logging.exception( - "Synchronization failed; the next run will retry" - ) + logging.exception("Synchronization failed; the next run will retry") if SYNC_INTERVAL_SECONDS == 0: break