Skip to content

Commit

Permalink
group uploaded files in an album, add missing __init__.py file, bump …
Browse files Browse the repository at this point in the history
…django-client-lib to v0.5.0
  • Loading branch information
tykling committed Nov 10, 2024
1 parent 80aef65 commit f2a3a27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ classifiers = [
]
dependencies = [
"typer-slim==0.12.5",
"bma-client-lib>=0.4.1",
"bma-client-lib>=0.5.0",
]
name = "bma-cli"
description = "BornHack Media Archive CLI Tool"
Expand Down
Empty file added src/bma_cli/__init__.py
Empty file.
10 changes: 9 additions & 1 deletion src/bma_cli/bma_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import time
import uuid
from datetime import UTC, datetime
from importlib.metadata import version as get_version
from pathlib import Path
from typing import TypedDict
Expand Down Expand Up @@ -34,7 +35,7 @@ class BaseJob(TypedDict):
"""Base class inherited by ImageConversionJob and ImageExifExtractionJob."""

job_type: str
uuid: uuid.UUID
job_uuid: uuid.UUID
basefile_uuid: uuid.UUID
user_uuid: uuid.UUID
client_uuid: uuid.UUID
Expand Down Expand Up @@ -119,12 +120,14 @@ def grind() -> None:
def upload(files: list[str]) -> None:
"""Loop over files and upload each."""
client, config = init()
file_uuids = []
for f in files:
pf = Path(f)
click.echo(f"Uploading file {f}...")
result = client.upload_file(path=pf, file_license=config["license"], attribution=config["attribution"])
metadata = result["bma_response"]
click.echo(f"File {metadata['uuid']} uploaded OK!")
file_uuids.append(metadata["uuid"])
# check for jobs
if metadata["jobs_unfinished"] == 0:
continue
Expand All @@ -142,6 +145,11 @@ def upload(files: list[str]) -> None:
klass = getattr(sys.modules[__name__], j["job_type"])
job = klass(**j)
handle_job(f=pf, job=job, client=client, config=config)
click.echo(f"Finished uploading {len(file_uuids)} files, creating album...")
now = datetime.isoformat(datetime.now(tz=UTC))
album = client.create_album(file_uuids=file_uuids, title=f"Created-{now}", description=f"Created-{now}")
url = f"{client.base_url}/albums/{album['uuid']}/"
click.echo(f"Created album {album['uuid']} with the uploaded file(s) see it at {url}")
click.echo("Done!")


Expand Down

0 comments on commit f2a3a27

Please sign in to comment.