Skip to content

Instantly share code, notes, and snippets.

@anthonygelibert
Created May 28, 2016 21:11
Show Gist options
  • Save anthonygelibert/2a709a232e8d55235fe2e0b8278ff141 to your computer and use it in GitHub Desktop.
Save anthonygelibert/2a709a232e8d55235fe2e0b8278ff141 to your computer and use it in GitHub Desktop.
Script to automate the downloading of French JO
#!/bin/sh
YEAR=`date +%Y`
MONTHDAY=`date +%m%d`
COMPLETE=`date +%Y%m%d`
DAY=`date +%j`
WEEK=`date +%V`
CHRONO_CORRECT=0
CHRONO_NB=`expr ${DAY} - ${WEEK} - ${CHRONO_CORRECT}`
CHRONO=$(jot -w "%04i" - $CHRONO_NB $CHRONO_NB)
FILENAME="Journal Officiel — ${COMPLETE}.pdf"
URL=https://www.journal-officiel.gouv.fr/verifier/getpdf.php\?fic\=../publication/${YEAR}/${MONTHDAY}/joe_${COMPLETE}_${CHRONO}_p000.pdf.sig
echo $URL
cd ~/Downloads
echo "\x1b[4;1mJe vais récupérer le JO du `date +"%A %_d %B %Y"`\x1b[0m"
curl "${URL}" > "${FILENAME}"
echo "\x1b[4;1mJe vérifie le fichier obtenu\x1b[0m"
if [ ! -z "`file -b "${FILENAME}" | grep -e "^PDF"`" ]; then
echo "\x1b[32mTout semble s'être bien déroulé\x1b[0m"
exit 0;
else
echo "\x1b[31mIl semble y avoir un problème…\x1b[0m"
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment