From 861f26ecea928525ced21f552092cddcd4ccf845 Mon Sep 17 00:00:00 2001 From: "Toerd@archlinux" Date: Wed, 29 Jul 2020 20:33:06 +0200 Subject: [PATCH] feat: Sends an email if new grades are available --- noten.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/noten.sh b/noten.sh index d660a8d..96c2aa6 100755 --- a/noten.sh +++ b/noten.sh @@ -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}; //{f=1}' | rg -o -e '(.*)' -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}; //{f=1}' | rg -o -e '(.*)' -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 \ No newline at end of file