first working version
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import json
|
||||
|
||||
import markdown
|
||||
from tinyhtml import h, raw, render
|
||||
from stellenangebot import Stellenangebot
|
||||
|
||||
def render_html(data: tuple[Stellenangebot, float]) -> str:
|
||||
job_data, score = data
|
||||
description = job_data.get("stellenangebotsBeschreibung", "")
|
||||
description_html = markdown.markdown(description, extensions=["nl2br"])
|
||||
|
||||
job_fields = []
|
||||
for field_name, field_value in job_data.items():
|
||||
if field_name in ("stellenangebotsTitel", "stellenangebotsBeschreibung"):
|
||||
continue
|
||||
|
||||
if isinstance(field_value, (dict, list)):
|
||||
field_value = json.dumps(field_value, ensure_ascii=False)
|
||||
|
||||
job_fields.append(h("p")(f"{field_name}: {field_value}"))
|
||||
|
||||
job_section = h("section")(
|
||||
h("h1")(f"{job_data.get('stellenangebotsTitel', '')} - {score:.2f}"),
|
||||
h("div")(raw(description_html)),
|
||||
h("hr"),
|
||||
*job_fields,
|
||||
)
|
||||
|
||||
return render(job_section)
|
||||
|
||||
|
||||
def write_html(html_parts: list[str]) -> None:
|
||||
stylesheet_link = '<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">'
|
||||
html_document = render(
|
||||
h("html")(
|
||||
h("head")(raw(stylesheet_link)),
|
||||
h("body")(*[raw(html_part) for html_part in html_parts]),
|
||||
)
|
||||
)
|
||||
|
||||
with open("stellenangebote.html", mode="w", encoding="utf-8") as html_file:
|
||||
html_file.write(html_document)
|
||||
html_file.write("\n")
|
||||
Reference in New Issue
Block a user