-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
26 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
""" | ||
import os | ||
from pdf2image import convert_from_path | ||
|
||
import highest | ||
# Generate the highest numebred pdf and take its number. | ||
MAX : int = highest.find_highest_numbered_pdf() | ||
|
||
# Generate and save the images. | ||
imgs = [] | ||
for i in range(MAX + 1): | ||
# Build the paths | ||
pdf_path = f'./pdf/{i}.pdf' | ||
img_path = f'./img/{i}.png' | ||
# Remove an image file if it has no corresponding pdf, | ||
# Assume it is a leftover artefact. | ||
# The images should strictly supervene on the pdf's. | ||
# This uses shortcircuiting. | ||
# This uses a technique know as "shortcircuiting". | ||
os.path.isfile(img_path) and not os.path.isfile(pdf_path) and os.remove(img_path) | ||
# Generate the images, but look if they already exist, because this proces is costly. | ||
if not os.path.isfile(img_path): | ||
# We look if the pdf actually exiss and don't assume this. | ||
# So we can skip editions. | ||
if os.path.isfile(pdf_path): | ||
print("extracting from pdf: " + str(i)) | ||
# Actually extract the image, well get an array back with one image in it. | ||
images = convert_from_path(pdf_path, first_page=1, last_page=1) | ||
# Loop through the array. | ||
for image in images: | ||
# Save the image. | ||
image.save(img_path, "PNG") | ||
else: | ||
# Report that we skipped the image. | ||
print(f"Thumbnail voor {img_path} bestaat al, skipping...") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
""" | ||
import os | ||
import re | ||
import highest | ||
# Calculate the highest numbered pdf and take its humber. | ||
MAX :int = highest.find_highest_numbered_pdf() | ||
|
||
|
||
|
||
# The string for a gallery item. | ||
gallery_item = '<a href="{pdf}" target="_blank"><img src="./img/{i}.png" alt="Title page of edition {i}"></a>' | ||
|
||
def generate_gallery(): | ||
""" | ||
""" | ||
editions_html = [] | ||
for i in range(MAX + 1,0,-1): | ||
pdf_file = f'./pdf/{i}.pdf' | ||
if os.path.isfile(pdf_file): | ||
editions_html.append(gallery_item.format(pdf=pdf_file, i=i)) | ||
return '\n'.join(editions_html) | ||
|
||
with open("template.html") as template, open("index.html", "w") as index: | ||
index.write(re.sub(r"<!--GALLERY-->",generate_gallery(),template.read())) | ||
with open("index.template.html") as template, open("index.html", "w") as index: | ||
replacement_string = r""" | ||
<p>YOU HAVE LANDED ON THE TEMPLATE PAGE OF <a href="./index.html">INDEX.HTML</a> THIS PARAGRAPH WILL BE REPLACED WITH THE GENERATED GALLERY!</p> | ||
""".strip() | ||
index.write(re.sub(replacement_string, generate_gallery(), template.read())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters