1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dm-scripts/scritti_ro.sh

35 lines
909 B
Bash

#!/usr/bin/env bash
set -euo pipefail
URL="https://didawiki.cli.di.unipi.it/doku.php/matematica/ro/start"
BASE="https://didawiki.cli.di.unipi.it"
TMPDIR=$(mktemp -d)
cleanup() { rm -rf "$TMPDIR"; }
trap cleanup EXIT
if [[ "${1:-}" == "--with-solutions" ]]; then
PREFIX="sc"
OUTFILE="soluzioni_ro_merge.pdf"
echo "Fetching Svolgimenti PDFs..."
else
PREFIX="c"
OUTFILE="testi_ro_merge.pdf"
echo "Fetching Testi PDFs..."
fi
curl -s "$URL" \
| grep -oP "/lib/exe/fetch\.php/matematica/ro/${PREFIX}\d{6}\.pdf" \
| sort -u \
| while read -r path; do
filename=$(basename "$path")
echo " Downloading $filename"
curl -s -o "$TMPDIR/$filename" "${BASE}${path}"
done
echo ""
echo "Merging PDFs into $OUTFILE..."
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$OUTFILE" "$TMPDIR"/*.pdf
echo "Done → $OUTFILE ($(wc -c < "$OUTFILE") bytes)"