Skip to content

Instantly share code, notes, and snippets.

@marvin
Created June 30, 2016 12:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marvin/bbbee1f89cf5b63818bc58bb49df6d55 to your computer and use it in GitHub Desktop.
Save marvin/bbbee1f89cf5b63818bc58bb49df6d55 to your computer and use it in GitHub Desktop.
vertrettungsplan checker für Tim
#!/bin/bash
#
# Quick and Dirty Vplan Checker
#
# - checks for vplan on industrieschule.de
# - downloads the pdfs and checks if it contains a certain class
# + if it matches converts the pdf to png and sends an email to an email list
#
# requires:
# - linux :-)
# - wget (zum downloaded der benoetigten dateien
# - poppler-tools (pdftotext zum auslesen der PDF)
# - ImageMagick (konvertiert pdf zu png)
# - mailx (fuer email senden)
#
# Writte by David Noelte for Little Timmy :-) @2016
#
# variables
# Variable USER,PASS anpassen wie erhalten
# Empfaenger von Email in MAILRCP Eintragen und bei bedarf MAILSUBJECT UND MAILMSG bearbeiten
#
URL=https://vplan.industrieschule.de/pdf
USER=Benutzername
PASS=Passwort
KLASSE="BKF14B"
MAILRCP=("meine@mail.com" "zweite@mail.com")
MAILSUBJECT="ACHTUNG! Vertrettung!"
MAILMSG=""
#DONT EDIT!!!!
WGETER="wget --quiet --http-user=$USER --http-password=$PASS --no-check-certificate $URL"
MAILCMD="echo $MAILMSG | mailx -a output.png -s '$MAILSUBJECT'"
#
# CODE STARTS HERE!
# get current index.html
eval "$WGETER/index.php"
# convert pdf to png
convert_pdf() {
eval "convert -density 150 $1 -quality 90 output.png"
}
# send email
send_mail() {
for i in "${MAILRCP[@]}"
do
echo "Sende Email zu $i ..."
eval "$MAILCMD $i"
done
}
# check for pdf files and download them
grep -ohE '([A-Za-z0-9_\.\\-]*)pdf' index.php | while read -r line ; do
echo "Downloading $line ..."
eval "$WGETER/$line"
echo "Pruefe Vertrettung ..."
if [ `pdftotext $line - | grep $KLASSE` ]
then
echo "$KLASSE hat Vertrettung siehe $line"
echo "Konvertiere PDF zu PNG ..."
convert_pdf $line
echo "Maile Vertrettungsplan ..."
send_mail
else
echo "Keine Vertrettung!"
fi
echo "Done!"
done
# clean up files
rm index.php
rm *.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment