cellarspoon
3 years ago
No known key found for this signature in database
GPG Key ID: 3789458B3D0C410
2 changed files with
15 additions and
0 deletions
-
README.md
-
app.py
|
@ -4,6 +4,8 @@ An app that uses the [`temp-index`](https://pypi.org/project/temp-index/) python |
|
|
|
|
|
|
|
|
## deploy it |
|
|
## deploy it |
|
|
|
|
|
|
|
|
|
|
|
[Install `pdfcpu`](https://github.com/pdfcpu/pdfcpu/releases) to `/usr/bin/pdfcpu`. |
|
|
|
|
|
|
|
|
``` |
|
|
``` |
|
|
sudo apt-get install libtiff5-dev libjpeg-dev libopenjp2-7-dev zlib1g-dev \ |
|
|
sudo apt-get install libtiff5-dev libjpeg-dev libopenjp2-7-dev zlib1g-dev \ |
|
|
libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk \ |
|
|
libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk \ |
|
|
|
@ -1,6 +1,8 @@ |
|
|
import os |
|
|
import os |
|
|
import random |
|
|
import random |
|
|
|
|
|
import shutil |
|
|
import string |
|
|
import string |
|
|
|
|
|
import subprocess |
|
|
from pathlib import Path |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
import petname |
|
|
import petname |
|
@ -56,6 +58,15 @@ class UploadForm(FlaskForm): |
|
|
petname = HiddenField("petname") |
|
|
petname = HiddenField("petname") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def impose_cards(fpath): |
|
|
|
|
|
"""Impose the cards with pdfcpu.""" |
|
|
|
|
|
if shutil.which("pdfcpu"): |
|
|
|
|
|
old_fpath = "{}.old.pdf".format(fpath) |
|
|
|
|
|
shutil.move(fpath, old_fpath) |
|
|
|
|
|
cmd = 'pdfcpu booklet -- "p:A4, border:on" {} 4 {}'.format(fpath, old_fpath) |
|
|
|
|
|
subprocess.run(cmd, shell=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/") |
|
|
@app.route("/") |
|
|
def home(): |
|
|
def home(): |
|
|
upload_form = UploadForm() |
|
|
upload_form = UploadForm() |
|
@ -120,6 +131,8 @@ def upload(): |
|
|
side_b, |
|
|
side_b, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
impose_cards(pdf_path) |
|
|
|
|
|
|
|
|
gen_msg = ( |
|
|
gen_msg = ( |
|
|
"Currently working on {}, click 'generate' to re-generate the same PDF" |
|
|
"Currently working on {}, click 'generate' to re-generate the same PDF" |
|
|
).format(pdf_name) |
|
|
).format(pdf_name) |
|
|