feat: Sends an email if new grades are available

master
Toerd@archlinux 5 years ago
parent 3203dc6198
commit 861f26ecea

@ -10,11 +10,11 @@ FU="https://www3.primuss.de/cgi-bin/pg_Notenbekanntgabe/showajax.pl"
USERNAME=phg0107
PASSWORD=lelelele
TMPPATH=$(mktemp -d)
FINALFILE=/some/path/to/result.txt
COOKIES=.cookies
HEADERS=.headers
rm $COOKIES
rm $HEADERS
COOKIES=$TMPPATH/.cookies
HEADERS=$TMPPATH/.headers
curl -s -L -c $COOKIES -D $HEADERS "$DEST" > /dev/null
LOGIN=$(cat $HEADERS | rg -o -e "Location: (.*)" -r '$1' | tail -1 | sed 's/\;.*?/?/')
@ -30,5 +30,11 @@ SAMLRESP=$(echo ${VALS[1]} | sed 's/=/%3D/g' | sed 's/+/%2B/g')
SESSION=$(curl -L -s -b $COOKIES -c $COOKIES -d "RelayState=$RELAYSTATE&SAMLResponse=$SAMLRESP" $SHIBBLE | rg -o -e 'name="Session" value="(.*)"' -r '$1' | head -1)
AJAXDATA=$(curl -s -b $COOKIES -c $COOKIES -d "User=$USERNAME&Session=$SESSION&Language=de&FH=fhin&Portal=1" $NOTEN | rg -o -e 'data: *"(.*)"' -r '$1' | head -1)
# Finally...
curl -s -b $COOKIES -c $COOKIES -d $AJAXDATA $FU | awk 'f{ if (/<\/tbody>/){printf "%s", buf; f=0; buf=""} else buf = buf $0 ORS}; /<tbody>/{f=1}' | rg -o -e '<b>(.*)</b>' -r '$1'
# Pipe output to file and if require perform futher formatting
cp $FINALFILE $TMPPATH
curl -s -b $COOKIES -c $COOKIES -d $AJAXDATA $FU | awk 'f{ if (/<\/tbody>/){printf "%s", buf; f=0; buf=""} else buf = buf $0 ORS}; /<tbody>/{f=1}' | rg -o -e '<b>(.*)</b>' -r '$1' | sudo -u http tee $FINALFILE
# If there is a change in the file, send an email
D=$(diff $FINALFILE $TMPPATH/noten.html)
if [ "$D" != "" ]; then
cat $FINALFILE | mail -s "NEUE NOTEN" meine@mail.de
fi
rm -rf $TMPPATH
Loading…
Cancel
Save