feature: download also other pages
This commit is contained in:
@@ -17,6 +17,7 @@ dl.download_question_metadata()
|
|||||||
dl.download_pictures()
|
dl.download_pictures()
|
||||||
dl.download_photos()
|
dl.download_photos()
|
||||||
dl.download_snippets()
|
dl.download_snippets()
|
||||||
|
dl.download_content()
|
||||||
|
|
||||||
# Build Everything:
|
# Build Everything:
|
||||||
bd.build_website()
|
bd.build_website()
|
||||||
|
|||||||
+27
-1
@@ -201,6 +201,11 @@ class Build:
|
|||||||
snippets[key] = snippets[key][3:-4]
|
snippets[key] = snippets[key][3:-4]
|
||||||
return snippets
|
return snippets
|
||||||
|
|
||||||
|
def __parse_contents(self):
|
||||||
|
with open("data/content.json") as f:
|
||||||
|
contents = json.load(f)
|
||||||
|
return contents
|
||||||
|
|
||||||
def __build_index(self, snippets):
|
def __build_index(self, snippets):
|
||||||
template = self.env.get_template("index.html")
|
template = self.env.get_template("index.html")
|
||||||
result = template.render({"snippets": snippets})
|
result = template.render({"snippets": snippets})
|
||||||
@@ -219,9 +224,30 @@ class Build:
|
|||||||
result = BeautifulSoup(result, "html.parser").prettify()
|
result = BeautifulSoup(result, "html.parser").prettify()
|
||||||
file.write(result)
|
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):
|
def build_website(self):
|
||||||
snippets = self.__parse_snippets()
|
snippets = self.__parse_snippets()
|
||||||
|
contents = self.__parse_contents()
|
||||||
self.__build_index(snippets)
|
self.__build_index(snippets)
|
||||||
self.__build_course_page(snippets, "kurse-karte", "kurse_vor_ort_karte")
|
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, "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
@@ -138,4 +138,18 @@ class Download:
|
|||||||
for snippet in tqdm(self.content_api.get("items/snippet"), desc="Downloading snippets"):
|
for snippet in tqdm(self.content_api.get("items/snippet"), desc="Downloading snippets"):
|
||||||
snippets[snippet["ident"]] = snippet["content"]
|
snippets[snippet["ident"]] = snippet["content"]
|
||||||
with open("data/snippets.json", "w", encoding="utf-8") as file:
|
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)
|
||||||
Reference in New Issue
Block a user