feat: allow to skip latex builds
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<svg width="356.104" height="127.52" viewBox="0 0 94.219 33.74" xmlns="http://www.w3.org/2000/svg"><path d="M77.133.931v1.606c7.736.513 13.83 6.008 14.69 13.197h1.698C92.83 8.057 86.213 1.486 77.133.931zm0 3.257v1.427c5.884.472 10.531 4.426 11.192 10.12h1.807c-.734-6.516-6.155-11.072-12.999-11.547zm0 2.853v1.712c3.903.491 6.9 3.343 7.58 6.981h1.696c-.675-4.612-4.435-8.182-9.276-8.693zm-41.531 9.808q0 2.116.381 3.852.381 1.736 1.059 3.006.72 1.27 1.693 1.99.974.677 2.201.677 1.186 0 2.16-.678 1.015-.72 1.693-1.99.677-1.27 1.058-3.005.381-1.736.381-3.852 0-2.075-.381-3.81-.381-1.778-1.058-3.006-.678-1.27-1.694-1.947-.973-.72-2.159-.72-1.227 0-2.201.72-.974.677-1.693 1.947-.678 1.228-1.059 3.006-.38 1.735-.38 3.81zm-8.212 0q0-3.81.973-6.9 1.016-3.133 2.794-5.335 1.82-2.201 4.276-3.386Q37.931 0 40.936 0q2.964 0 5.461 1.228 2.498 1.185 4.276 3.386 1.778 2.202 2.752 5.334 1.016 3.09 1.016 6.9 0 3.81-1.016 6.943-.974 3.09-2.752 5.334-1.778 2.202-4.276 3.43-2.497 1.185-5.46 1.185-3.006 0-5.504-1.186-2.455-1.227-4.276-3.429-1.778-2.243-2.794-5.334-.973-3.132-.973-6.942zm-5.927-8.89H10.414l-.55 3.513q.762-.084 1.397-.127.635-.084 1.312-.084 2.413 0 4.487.846 2.075.847 3.556 2.329 1.482 1.481 2.329 3.556.846 2.074.846 4.53 0 2.582-.973 4.656-.932 2.074-2.667 3.556-1.736 1.44-4.234 2.201-2.497.805-5.545.805-2.879 0-5.504-.72Q2.286 32.343 0 30.903l1.228-7.79q2.116 1.821 4.318 2.795 2.201.931 4.19.931 2.54 0 4.022-1.354 1.482-1.397 1.482-3.43 0-2.37-1.99-3.81-1.99-1.481-5.207-1.481-1.439 0-2.963.339-1.524.296-3.006.973L4.741.931h16.722zM75.89.889c-2.54 0-4.884.438-7.028 1.312-2.145.847-4.008 2.018-5.588 3.514a16.126 16.126 0 00-3.726 5.164 14.913 14.913 0 00-1.312 6.181c0 .706.085 1.524.254 2.456.198.903.494 1.834.889 2.794a14.39 14.39 0 001.524 2.71 9.41 9.41 0 002.244 2.242H57.6v6.478h15.875v-7.112a8.189 8.189 0 01-2.624-1.313 10.73 10.73 0 01-2.075-2.159 11.886 11.886 0 01-1.355-2.752 10.382 10.382 0 01-.465-3.047c0-1.214.226-2.343.677-3.387a9.412 9.412 0 011.905-2.752 9.165 9.165 0 012.837-1.862c1.1-.452 2.285-.677 3.555-.677h.012V.89h-.054zm8.95 15.97c.009.166.024.329.024.498 0 1.016-.17 2.031-.508 3.047A9.996 9.996 0 0183 23.156a9.399 9.399 0 01-2.074 2.16 8.189 8.189 0 01-2.625 1.312v7.112h15.917v-6.478h-5.503a9.407 9.407 0 002.244-2.243 12.763 12.763 0 001.482-2.71c.395-.959.677-1.89.846-2.793.198-.932.297-1.75.297-2.456 0-.067-.004-.134-.005-.201z" font-weight="700" font-size="42.333" font-family="Futura" fill="#777"/></svg>
|
||||
|
After Width: | Height: | Size: 2.4 KiB |
@@ -1,13 +1,12 @@
|
||||
|
||||
import api.directus as directus
|
||||
import src.build as build
|
||||
import src.config as config
|
||||
import src.download as download
|
||||
|
||||
conf = config.Config()
|
||||
api = directus.DirectusAPI(conf)
|
||||
dl = download.Download(api)
|
||||
bd = build.Build()
|
||||
api = directus.DirectusAPI(conf)
|
||||
dl = download.Download(api, conf)
|
||||
bd = build.Build()
|
||||
|
||||
# Download the text files:
|
||||
dl.download_edition("N")
|
||||
@@ -22,4 +21,3 @@ bd.build_edition("N")
|
||||
|
||||
# Build assets:
|
||||
bd.build_assets()
|
||||
|
||||
|
||||
+52
-68
@@ -1,21 +1,19 @@
|
||||
import json
|
||||
import multiprocessing
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from joblib import Memory, Parallel, delayed
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
class Download:
|
||||
def __init__(self, api):
|
||||
def __init__(self, api, config):
|
||||
self.api = api
|
||||
|
||||
def download_edition(self, edition) :
|
||||
self.config = config
|
||||
|
||||
in_edition = self.api.get_one(
|
||||
"items/edition",
|
||||
{"filter": {"ident": {"_eq": edition}}}
|
||||
)
|
||||
def download_edition(self, edition):
|
||||
in_edition = self.api.get_one("items/edition", {"filter": {"ident": {"_eq": edition}}})
|
||||
|
||||
in_chapters = self.api.get(
|
||||
"items/chapter",
|
||||
@@ -24,8 +22,7 @@ class Download:
|
||||
|
||||
out_chapters = []
|
||||
|
||||
for in_chapter in tqdm(in_chapters, desc="Downloading edition"):
|
||||
|
||||
for in_chapter in tqdm(in_chapters, desc="Downloading edition"):
|
||||
in_sections = self.api.get(
|
||||
"items/section",
|
||||
{"filter": {"chapter": {"chapter_id": {"_eq": in_chapter["id"]}}}},
|
||||
@@ -33,49 +30,47 @@ class Download:
|
||||
|
||||
out_chapters.append(
|
||||
{
|
||||
"title" : in_chapter["title"],
|
||||
"abstract" : in_chapter["abstract"],
|
||||
"ident" : in_chapter["ident"],
|
||||
"video_url" : in_chapter["video_url"],
|
||||
"sections" : [],
|
||||
"title": in_chapter["title"],
|
||||
"abstract": in_chapter["abstract"],
|
||||
"ident": in_chapter["ident"],
|
||||
"video_url": in_chapter["video_url"],
|
||||
"sections": [],
|
||||
}
|
||||
)
|
||||
|
||||
for in_section in in_sections:
|
||||
out_chapters[-1]["sections"].append(
|
||||
{
|
||||
"title" : in_section["title"],
|
||||
"ident" : in_section["ident"],
|
||||
"status" : in_section["status"],
|
||||
"class" : in_section["class"],
|
||||
"content" : in_section["content"],
|
||||
"slide" : in_section["slide"],
|
||||
"video" : in_section["video_url"],
|
||||
"questions" : [],
|
||||
"title": in_section["title"],
|
||||
"ident": in_section["ident"],
|
||||
"status": in_section["status"],
|
||||
"class": in_section["class"],
|
||||
"content": in_section["content"],
|
||||
"slide": in_section["slide"],
|
||||
"video": in_section["video_url"],
|
||||
"questions": [],
|
||||
}
|
||||
)
|
||||
|
||||
with open("data/book_"+edition+".json", "w", encoding="utf-8") as file:
|
||||
with open("data/book_" + edition + ".json", "w", encoding="utf-8") as file:
|
||||
json.dump(out_chapters, file, ensure_ascii=False, indent=4)
|
||||
|
||||
def download_question_metadata(self) :
|
||||
|
||||
def download_question_metadata(self):
|
||||
questions = self.api.get(
|
||||
"items/questions",
|
||||
params={"filter": {"class_3": {"_in": [1,2,3]}}, "sort": "position", "limit": -1}
|
||||
"items/questions", params={"filter": {"class_3": {"_in": [1, 2, 3]}}, "sort": "position", "limit": -1}
|
||||
)
|
||||
|
||||
result = {}
|
||||
|
||||
for question in tqdm(questions, desc="Downloading metadata"):
|
||||
result[question["id"]] = {
|
||||
"number": question["number"],
|
||||
"number": question["number"],
|
||||
"picture_question": question["picture_question"] if question["picture_question"] is not None else "",
|
||||
"picture_a": question["picture_a"] if question["picture_a"] is not None else "",
|
||||
"picture_b": question["picture_b"] if question["picture_b"] is not None else "",
|
||||
"picture_c": question["picture_c"] if question["picture_c"] is not None else "",
|
||||
"picture_d": question["picture_d"] if question["picture_d"] is not None else "",
|
||||
"layout": question["layout"] if question["layout"] is not None else "",
|
||||
"picture_a": question["picture_a"] if question["picture_a"] is not None else "",
|
||||
"picture_b": question["picture_b"] if question["picture_b"] is not None else "",
|
||||
"picture_c": question["picture_c"] if question["picture_c"] is not None else "",
|
||||
"picture_d": question["picture_d"] if question["picture_d"] is not None else "",
|
||||
"layout": question["layout"] if question["layout"] is not None else "",
|
||||
}
|
||||
|
||||
# Serializing json:
|
||||
@@ -83,60 +78,49 @@ class Download:
|
||||
json.dump(result, f, indent=4)
|
||||
f.close()
|
||||
|
||||
def download_photos(self) :
|
||||
|
||||
photos = self.api.get(
|
||||
"items/Fotos",
|
||||
params={ "limit": -1 }
|
||||
)
|
||||
def download_photos(self):
|
||||
photos = self.api.get("items/Fotos", params={"limit": -1})
|
||||
|
||||
for photo in tqdm(photos, desc="Downloading photos"):
|
||||
data = self.api.get_file("assets/" + photo["photo"])
|
||||
file = open("./data/photos/" + str(photo["id"]) + ".jpg", "wb")
|
||||
file.write(data)
|
||||
file.close()
|
||||
with open(f"./data/photos/{photo['id']}.jpg", "wb") as file:
|
||||
file.write(data)
|
||||
|
||||
def __symlink_pictures(self) :
|
||||
def __symlink_pictures(self):
|
||||
os.chdir("./data/pictures")
|
||||
if not os.path.islink("foto"):
|
||||
os.system("ln -s ../photos foto")
|
||||
os.chdir("../..")
|
||||
|
||||
def download_pictures(self) :
|
||||
def download_pictures(self):
|
||||
self.__symlink_pictures()
|
||||
|
||||
memory=Memory("./cache", verbose=0)
|
||||
|
||||
memory = Memory("./cache", verbose=0)
|
||||
|
||||
@memory.cache
|
||||
def build_picture(picture) :
|
||||
def build_picture(picture):
|
||||
pid = picture["id"]
|
||||
|
||||
if "\\begin{document}" in picture["latex"] or "\\begin{table}" in picture["latex"]: # Workaround, if the picture contains a document class it should be ignored!
|
||||
|
||||
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
|
||||
|
||||
with open(f"./data/pictures/{pid}.tex", 'w', encoding='utf-8') as file:
|
||||
# Write the auxilary LaTeX file:
|
||||
file.write(f"\\documentclass{{BNetzA-Fragenkatalog}}\\DARCimageOnly{{9cm}}{{{picture['id']}include}}")
|
||||
file.close()
|
||||
|
||||
if self.config.no_latex:
|
||||
shutil.copyfile("./assets/images/50ohm_gray.svg", f"./data/pictures/{pid}.svg")
|
||||
else:
|
||||
with open(f"./data/pictures/img/{pid}include.tex", "w") as file:
|
||||
file.write(picture["latex"])
|
||||
with open(f"./data/pictures/{pid}.tex", "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 ./data/pictures/{pid}.tex > /dev/null 2>&1")
|
||||
# Convert the PDF to SVG:
|
||||
os.system(f"pdftocairo -svg data/pictures/{picture['id']}.pdf - > data/pictures/{picture['id']}.svg")
|
||||
os.system(f"pdftocairo -svg data/pictures/{pid}.pdf - > data/pictures/{pid}.svg")
|
||||
|
||||
pictures = self.api.get(
|
||||
"items/pictures",
|
||||
params={ "limit": -1 }
|
||||
)
|
||||
|
||||
for picture in tqdm(pictures, desc="Download all pictures"):
|
||||
latex = picture["latex"]
|
||||
with open("./data/pictures/img/" + str(picture["id"]) + "include.tex", "w") as file:
|
||||
file.write(latex)
|
||||
file.close()
|
||||
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")
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user