From 9f0d0ffc3a981b99ff6c8faa430797c2e2e73099 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 9 Nov 2025 08:42:29 +0100 Subject: [PATCH 1/4] feature: download svgs instead of building them --- build.py | 2 +- src/download.py | 50 ++++++++++--------------------------------------- 2 files changed, 11 insertions(+), 41 deletions(-) diff --git a/build.py b/build.py index e5143dc..2cd7c8f 100644 --- a/build.py +++ b/build.py @@ -14,8 +14,8 @@ dl.download_edition("N") # Download additional files: dl.download_question_metadata() -dl.download_pictures() dl.download_photos() +dl.download_pictures() dl.download_includes() dl.download_snippets() dl.download_content() diff --git a/src/download.py b/src/download.py index 9459417..301d69f 100644 --- a/src/download.py +++ b/src/download.py @@ -1,9 +1,5 @@ import json -import multiprocessing -import os -import shutil -from joblib import Memory, Parallel, delayed from tqdm import tqdm from api.directus import DirectusAPI @@ -97,50 +93,24 @@ class Download: for photo in tqdm(photos, desc="Downloading photos"): data = self.api.get_file("assets/" + photo["photo"]) - with (self.config.p_data_photos / f"{photo['id']}.jpg").open("wb") as file: + with (self.config.p_data_photos / f"{photo["id"]}.jpg").open("wb") as file: file.write(data) def download_pictures(self): self.config.p_data_pictures.mkdir(parents=True, exist_ok=True) - # Symlink photos, so LaTeX can access these assets to render into graphics. - foto_link = self.config.p_data_pictures / "foto" - if not foto_link.is_symlink(): - foto_link.symlink_to(self.config.p_data_photos) - memory = Memory("./cache", verbose=0) + pictures = self.api.get("items/pictures", { "limit": -1 }) - @memory.cache - def build_picture(picture): - pid = picture["id"] + for picture in tqdm(pictures, desc="Downloading pictures") : - if ( - "\\begin{document}" in picture["latex"] or "\\begin{table}" in picture["latex"] - ): # Workaround, if the picture contains a document class it should be ignored! - return + # Download LaTeX Sources: + with (self.config.p_data_pictures / f"{picture["id"]}include.tex").open("w") as file: + file.write(picture["latex"]) - if self.config.no_latex: - shutil.copyfile("./assets/images/50ohm_gray.svg", self.config.p_data_pictures / f"{pid}.svg") - else: - with (self.config.p_data_pictures / f"img/{pid}include.tex").open("w") as file: - file.write(picture["latex"]) - - aux_file = self.config.p_data_photos / f"{pid}.tex" - with aux_file.open("w", encoding="utf-8") as file: - # Write the auxilary LaTeX file: - file.write(f"\\documentclass{{BNetzA-Fragenkatalog}}\\DARCimageOnly{{9cm}}{{{pid}include}}") - # Build the picture: - os.system(f"latexmk -lualatex -f -interaction=nonstopmode {aux_file} > /dev/null 2>&1") - # Convert the PDF to SVG: - os.system( - "pdftocairo -svg" - f"{self.config.p_data_pictures / f'{pid}.pdf'} - > {self.config.p_data_pictures / f'{pid}.svg'}" - ) - - pictures = self.api.get("items/pictures", params={"limit": -1}) - - Parallel(n_jobs=multiprocessing.cpu_count())( - delayed(build_picture)(picture) for picture in tqdm(pictures, desc="Build All Pictures") - ) + # Download SVGs: + data = self.api.get_file(f"assets/{picture["picture"]}") + with (self.config.p_data_pictures / f"{picture["id"]}.svg").open("wb") as file: + file.write(data) def download_includes(self): includes = self.api.get("items/include", params={"limit": -1}) From 0df7d575953be0fce007b9c7857c1d59cf7f41de Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 9 Nov 2025 10:43:44 +0100 Subject: [PATCH 2/4] feature: enable auto format on save --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8decbe7..28b391b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, "[python]": { + "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.fixAll.ruff": "explicit", "source.organizeImports.ruff": "explicit" From bf94317945a7487cf6fe3a55fb46b02333b0155f Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 9 Nov 2025 10:44:07 +0100 Subject: [PATCH 3/4] fix: format to pass ci --- src/download.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/download.py b/src/download.py index 301d69f..a0926ef 100644 --- a/src/download.py +++ b/src/download.py @@ -93,23 +93,22 @@ class Download: for photo in tqdm(photos, desc="Downloading photos"): data = self.api.get_file("assets/" + photo["photo"]) - with (self.config.p_data_photos / f"{photo["id"]}.jpg").open("wb") as file: + with (self.config.p_data_photos / f"{photo['id']}.jpg").open("wb") as file: file.write(data) def download_pictures(self): self.config.p_data_pictures.mkdir(parents=True, exist_ok=True) - pictures = self.api.get("items/pictures", { "limit": -1 }) - - for picture in tqdm(pictures, desc="Downloading pictures") : + pictures = self.api.get("items/pictures", {"limit": -1}) + for picture in tqdm(pictures, desc="Downloading pictures"): # Download LaTeX Sources: - with (self.config.p_data_pictures / f"{picture["id"]}include.tex").open("w") as file: + with (self.config.p_data_pictures / f"{picture['id']}include.tex").open("w") as file: file.write(picture["latex"]) # Download SVGs: - data = self.api.get_file(f"assets/{picture["picture"]}") - with (self.config.p_data_pictures / f"{picture["id"]}.svg").open("wb") as file: + data = self.api.get_file(f"assets/{picture['picture']}") + with (self.config.p_data_pictures / f"{picture['id']}.svg").open("wb") as file: file.write(data) def download_includes(self): From 339966c5e53dedaf763dd8500fd52ab64e89ff41 Mon Sep 17 00:00:00 2001 From: Tim Grelka Date: Sun, 9 Nov 2025 10:59:57 +0100 Subject: [PATCH 4/4] docs: update comments --- src/download.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/download.py b/src/download.py index a0926ef..4c9d586 100644 --- a/src/download.py +++ b/src/download.py @@ -102,11 +102,11 @@ class Download: pictures = self.api.get("items/pictures", {"limit": -1}) for picture in tqdm(pictures, desc="Downloading pictures"): - # Download LaTeX Sources: + # Save LaTeX sources to file with (self.config.p_data_pictures / f"{picture['id']}include.tex").open("w") as file: file.write(picture["latex"]) - # Download SVGs: + # Download SVG data = self.api.get_file(f"assets/{picture['picture']}") with (self.config.p_data_pictures / f"{picture['id']}.svg").open("wb") as file: file.write(data)