From 66a099e88fcd8d8047ddc6097333b3f03646b2bc Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Sun, 10 Nov 2024 19:39:39 +0100 Subject: [PATCH] add create_album method --- src/bma_client_lib/__init__.py | 4 ++++ src/bma_client_lib/bma_client.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/bma_client_lib/__init__.py b/src/bma_client_lib/__init__.py index 0efd673..d1b5a25 100644 --- a/src/bma_client_lib/__init__.py +++ b/src/bma_client_lib/__init__.py @@ -1 +1,5 @@ +"""Convenience import.""" + from .bma_client import BmaClient + +__all__ = ["BmaClient"] diff --git a/src/bma_client_lib/bma_client.py b/src/bma_client_lib/bma_client.py index d68a53c..c4b24ef 100644 --- a/src/bma_client_lib/bma_client.py +++ b/src/bma_client_lib/bma_client.py @@ -6,6 +6,7 @@ import uuid from fractions import Fraction from http import HTTPStatus +from importlib.metadata import PackageNotFoundError, version from io import BytesIO from pathlib import Path from typing import TYPE_CHECKING, TypeAlias @@ -14,9 +15,6 @@ import httpx import magic from PIL import Image, ImageOps -from importlib.metadata import PackageNotFoundError -from importlib.metadata import version - logger = logging.getLogger("bma_client") @@ -325,3 +323,14 @@ def get_exif(self, fname: Path) -> ExifExtractionJobResult: grouped[group] = {} grouped[group][key] = str(value) return grouped + + def create_album(self, file_uuids: list[uuid.UUID], title: str, description: str) -> dict[str, str]: + """Create an album.""" + url = self.base_url + "/api/v1/json/albums/create/" + data = { + "files": file_uuids, + "title": title, + "description": description, + } + r = self.client.post(url, json=data).raise_for_status() + return r.json()["bma_response"]