Add batch import script

This commit is contained in:
thePR0M3TH3AN
2025-06-17 21:08:18 -04:00
parent 48c4bed936
commit fe1f778dba
5 changed files with 46 additions and 6 deletions

1
.gitignore vendored
View File

@@ -15,3 +15,4 @@ tmp*/
Thumbs.db
*~
*.swp
imports/*.json

View File

@@ -81,6 +81,17 @@ Additional documentation is available in the `src/` directory; see [src/README.m
2. Run `./src/create_flyer.sh` and follow the prompts, or use `./src/create_flyer.sh --from-pdf path/to/form.pdf`.
3. Host the generated `host/<subdomain>` directory.
## Batch Import
Place configuration files in an `imports/` directory at the project root. Run
```bash
./src/import_from_json.sh
```
Each JSON file is copied to `src/config.json` and processed with
`create_flyer.sh --no-interaction`. Existing folders under `host/` with the
same subdomain are removed before new files are written.
## Hosting Options
The folder under `host/<subdomain>` contains all of the files needed to serve
the flyer as a static website. A few easy ways to make it publicly accessible

0
imports/.gitkeep Normal file
View File

View File

@@ -15,9 +15,10 @@ done
CONFIG_PATH="src/config.json"
FROM_PDF=""
NON_INTERACTIVE=0
usage() {
echo "Usage: $0 [-c config_path] [--from-pdf PDF]"
echo "Usage: $0 [-c config_path] [--from-pdf PDF] [--no-interaction]"
echo "Create and deploy a flyer based on config.json."
exit 1
}
@@ -33,6 +34,10 @@ while [[ $# -gt 0 ]]; do
FROM_PDF="$2"
shift 2
;;
-n|--no-interaction)
NON_INTERACTIVE=1
shift
;;
-h|--help)
usage
;;
@@ -89,11 +94,13 @@ update_config_from_pdf() {
rm -rf "$tmpdir"
}
if [[ $NON_INTERACTIVE -eq 0 ]]; then
if [[ -n "$FROM_PDF" ]]; then
update_config_from_pdf
else
update_config_interactive
fi
fi
# Regenerate QR codes based on the updated configuration
( cd src && ./generate_qr.sh )

21
src/import_from_json.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
set -euo pipefail
IMPORT_DIR="imports"
shopt -s nullglob
files=("$IMPORT_DIR"/*.json)
if [[ ${#files[@]} -eq 0 ]]; then
echo "No JSON files found in $IMPORT_DIR"
exit 0
fi
for json in "${files[@]}"; do
echo "Processing $json"
cp "$json" src/config.json
subdomain=$(jq -r '.subdomain' "$json")
dest="host/$subdomain"
rm -rf "$dest"
./src/create_flyer.sh --no-interaction
done