summaryrefslogtreecommitdiff
path: root/netzbon/generate-letter.sh
diff options
context:
space:
mode:
Diffstat (limited to 'netzbon/generate-letter.sh')
-rwxr-xr-xnetzbon/generate-letter.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/netzbon/generate-letter.sh b/netzbon/generate-letter.sh
new file mode 100755
index 0000000..272463c
--- /dev/null
+++ b/netzbon/generate-letter.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+# This script is in the public domain.
+#
+# Call with the JSON file (like test.json) with
+# an array of merchants to generate letters for!
+#
+# You must export
+#
+# export BASE_URL=https://e.netzbon-basel.ch/
+#
+# before running this script!
+#
+
+set -eu
+LENGTH=$(jq length < $1)
+echo "Generating $LENGTH letters for ${BASE_URL}"
+DOMAIN=$( echo "${BASE_URL}" | sed -e "s/https:\/\///" | sed -e "s/\/$//")
+mkdir -p export
+mkdir -p tmp
+
+for n in $(seq 1 $LENGTH)
+do
+ echo "Processing merchant $n"
+ INDEX=$(expr $n - 1 || true)
+ ID=$(jq -r .[$INDEX].id < $1)
+
+ jq ".[$INDEX]" < $1 | jq '.domain="'"${DOMAIN}"'"' > "tmp/${ID}.json"
+ cd tmp
+ ../render.py "${ID}.json" < ../template_de.tex.j2 > "${ID}.tex"
+ pdflatex "${ID}.tex" < /dev/null &> /dev/null || true
+ pdflatex "${ID}.tex" < /dev/null &> /dev/null || true
+ pdflatex "${ID}.tex" < /dev/null
+ mv "${ID}.pdf" ../export/
+ cd ..
+
+ echo "Done with ${ID}"
+done
+
+pdftk export/*.pdf cat output result.pdf
+echo "Combined letters are in 'result.pdf'"