From 64bf2cb0c4e24341a9062aa760e302126fb4e13e Mon Sep 17 00:00:00 2001 From: "Prof. Dr. Matthias Jung DL9MJ" Date: Wed, 28 May 2025 00:01:23 +0200 Subject: [PATCH] feature: download also other pages --- build.py | 1 + src/build.py | 28 +++++++++++++++++++++++++++- src/download.py | 16 +++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/build.py b/build.py index 6bef138..3e8b1db 100644 --- a/build.py +++ b/build.py @@ -17,6 +17,7 @@ dl.download_question_metadata() dl.download_pictures() dl.download_photos() dl.download_snippets() +dl.download_content() # Build Everything: bd.build_website() diff --git a/src/build.py b/src/build.py index d7f409c..8adedd3 100644 --- a/src/build.py +++ b/src/build.py @@ -201,6 +201,11 @@ class Build: snippets[key] = snippets[key][3:-4] return snippets + def __parse_contents(self): + with open("data/content.json") as f: + contents = json.load(f) + return contents + def __build_index(self, snippets): template = self.env.get_template("index.html") result = template.render({"snippets": snippets}) @@ -219,9 +224,30 @@ class Build: result = BeautifulSoup(result, "html.parser").prettify() file.write(result) + def __build_html_page(self, contents, page): + for content in contents: + if content["url_part"] == page: + + if content["sidebar"] is None: + result = content["content"] + else: + result = '
\n' + result += f'
{content["content"]}
\n' + result += f'
{content["sidebar"]}
\n' + result += '
\n' + + with open(f"build/{page}.html", "w") as file: + + result = self.__build_page(result) + result = BeautifulSoup(result, "html.parser").prettify() + file.write(result) + def build_website(self): snippets = self.__parse_snippets() + contents = self.__parse_contents() self.__build_index(snippets) self.__build_course_page(snippets, "kurse-karte", "kurse_vor_ort_karte") self.__build_course_page(snippets, "kurse-liste", "kurse_vor_ort_liste") - self.__build_course_page(snippets, "patenkarte", "patenkarte") \ No newline at end of file + self.__build_course_page(snippets, "patenkarte", "patenkarte") + self.__build_html_page(contents, "pruefung") + self.__build_html_page(contents, "infos") \ No newline at end of file diff --git a/src/download.py b/src/download.py index 89146c2..0488f11 100644 --- a/src/download.py +++ b/src/download.py @@ -138,4 +138,18 @@ class Download: for snippet in tqdm(self.content_api.get("items/snippet"), desc="Downloading snippets"): snippets[snippet["ident"]] = snippet["content"] with open("data/snippets.json", "w", encoding="utf-8") as file: - json.dump(snippets, file, ensure_ascii=False, indent=4) \ No newline at end of file + json.dump(snippets, file, ensure_ascii=False, indent=4) + + def download_content(self): + contents = [] + for content in self.content_api.get("items/content"): #tqdm(self.content_api.get("items/content"), desc="Downloading content"): + contents.append( + { + "url_part": content["url_part"], + "content": content["content"], + "sidebar": content["sidebar"], + } + ) + + with open("data/content.json", "w", encoding="utf-8") as file: + json.dump(contents, file, ensure_ascii=False, indent=4) \ No newline at end of file