Last active
April 21, 2019 06:06
-
-
Save zupo/18d4cea83dfdde4f637a25531d5a196a to your computer and use it in GitHub Desktop.
Export Plone site into a directory tree of PDFs.
This file contains hidden or 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
# spin up a local instance | |
# portal_workflows, allow everything for Anonymous, click update portal security | |
# bin/instance debug | |
# >>> for brain in app.Plone.portal_catalog(): | |
# >>> print brain.getURL().split('http://nohost/Plone/')[1] | |
# Paste paths into paths.txt | |
# More info on https://blog.niteo.co/export-plone-to-pdfs/ | |
from subprocess import check_output | |
import os.path | |
f = open("paths.txt", "r") | |
for path in f.readlines(): | |
path = path[:-1] # remove \n | |
filename = path.split("/")[-1] | |
folder = "/".join(path.split("/")[:-1]) | |
if os.path.isfile(f"output/{folder}/{filename}") or os.path.isfile( | |
f"output/{folder}/{filename}.pdf" | |
): | |
print(f"skipping: {folder}/{filename}") | |
continue | |
else: | |
print(f"processing: {path}") | |
cmd = f"mkdir -p output/{folder}" | |
output = check_output(cmd, shell=True).decode() | |
if filename.endswith(("pdf", "jpg", "jpeg", "png")): | |
cmd = f"wget http://localhost:8080/Plone/{path}" | |
else: | |
cmd = ( | |
"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome " | |
"--headless --disable-gpu --no-margins --run-all-compositor-stages-before-draw " | |
f"--print-to-pdf={filename}.pdf " | |
f"http://localhost:8080/Plone/{path}" | |
) | |
check_output(cmd, shell=True, cwd=f"output/{folder}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment