Verified Commit 141ed235 authored by Jakob Moser's avatar Jakob Moser
Browse files

Add rudimentary handling of certification requests

parent 295c0aec
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
import json
from itertools import repeat
from json import JSONDecodeError
from pathlib import Path
from typing import Annotated

from multiprocessing import Pool

from babel import Locale

from coliverter.certifications.from_dict import from_dict as certification_from_dict
from coliverter.documents.Document import Document
from coliverter.documents.DocumentType import DocumentType
from coliverter.documents.transform.TransformError import TransformError
@@ -42,7 +47,21 @@ def _convert_single(
    document_type: DocumentType | None,
) -> None:
    data = read(input_path)
    # TODO Handle other types than markdown

    # TODO Replace this with a more elegant way of checking if data is a request dictionary
    try:
        data_dict = json.loads(data)
        certification = certification_from_dict(data_dict)

        match output_format:
            case FileFormat.HTML:
                write(certification.html(Locale("de")), output_path)
            case FileFormat.PDF:
                # TODO Set metadata.json name
                write(certification.pdf(Locale("de")), output_path)
    except JSONDecodeError:
        pass

    document = Document.from_markdown(data, document_type)

    match output_format: