I couldn't leave it quite that ugly

This commit is contained in:
Askill 2024-01-29 19:41:39 +01:00
parent f18ba36515
commit d3e43546bb
3 changed files with 37 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
front/*
back/*
out/*
*.pdf
.vscode/settings.json

31
combine.py Normal file
View File

@ -0,0 +1,31 @@
import os
import glob
def get_ordered_files(dir_name):
# Get list of all files only in the given directory
list_of_files = filter(os.path.isfile, glob.glob(dir_name + '/*'))
# Sort list of files based on creation time in ascending order
list_of_files = sorted(list_of_files, key=os.path.getctime)
return list_of_files
def site(path, out, reversed):
f = get_ordered_files(path)
if reversed:
f = f[::-1]
f = [f'"{s}"' for s in f]
s = ' '.join(f)
exec_string = f"img2pdf {s} -o {out}"
return exec_string
front_out = "out/front.pdf"
back_out = "out/back.pdf"
merged_out = "out/merged.pdf"
os.system(site("./front", front_out, False))
os.system(site("./back", back_out, True))
os.system(f"pdftk A={front_out} B={back_out} shuffle A B output {merged_out}")

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
img2pdf