feature: download also other pages

This commit is contained in:
Prof. Dr. Matthias Jung DL9MJ
2025-06-24 22:04:13 +02:00
committed by Tim Grelka
parent 80b184c678
commit 64bf2cb0c4
3 changed files with 43 additions and 2 deletions
+1
View File
@@ -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()
+27 -1
View File
@@ -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 = '<div class="fiftyohm-content-2cols">\n'
result += f'<div>{content["content"]}</div>\n'
result += f'<div>{content["sidebar"]}</div>\n'
result += '</div>\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")
self.__build_course_page(snippets, "patenkarte", "patenkarte")
self.__build_html_page(contents, "pruefung")
self.__build_html_page(contents, "infos")
+15 -1
View File
@@ -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)
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)