diff options
author | Joris | 2023-09-16 18:28:16 +0200 |
---|---|---|
committer | Joris | 2023-09-16 18:31:24 +0200 |
commit | 06f045e90bb57c36738e58ee6830e2a2391bc6a3 (patch) | |
tree | a5b65b048c103b4ea0e5d3c0fa5e115cbaf3cf5f /src/library | |
parent | 230f2e0623d22af6e68466884bd5dea5dcb846dc (diff) |
Migrate CLI to python
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/__init__.py | 0 | ||||
-rw-r--r-- | src/library/command.py | 21 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/library/__init__.py b/src/library/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/library/__init__.py diff --git a/src/library/command.py b/src/library/command.py new file mode 100644 index 0000000..6b8577e --- /dev/null +++ b/src/library/command.py @@ -0,0 +1,21 @@ +import glob +import json +import os +import tomllib + +def run(book_library): + print(get(book_library)) + +def get(book_library): + metadatas = [] + + for path in glob.glob(f'{book_library}/**/metadata.toml', recursive=True): + with open(path, 'rb') as f: + directory = os.path.dirname(os.path.realpath(path)) + metadata = tomllib.load(f) + for p in glob.glob(f'{directory}/cover.*'): + metadata['cover'] = p + break + metadatas.append(metadata) + + return json.dumps(metadatas) |