Last active
October 7, 2021 06:02
-
-
Save p-fruck/8a5ad72db014d1e89d1720fc7e23127c to your computer and use it in GitHub Desktop.
Bash script for fetching DHBW Dualis grades
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Dualis notification script by p-fruck <dev@p-fruck.de> | |
# License: Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0) | |
# | |
# This script is intended to be used within a cronjob and will use the | |
# notify-send command once it detects new grades. However you can simply | |
# modify the code and use e.g. email notification instead. Have fun. | |
username=user@dhbw.de | |
password=Password1! | |
baseurl="https://dualis.dhbw.de/scripts/mgrqispi.dll" | |
saves=$(dirname "$0")/.dualis.save | |
# This function is your entry-point to the code. It takes two parameters: | |
# $1: The grade you've achieved | |
# $2: The course you've achieved the grade in | |
# Now go ahead an decide what you do with the information, | |
# or use notify-send like I do by default. | |
function grade_fetched() { | |
info="$1 $2" | |
touch "${saves}" | |
isnew=$(grep "$info" "${saves}") | |
# check if grade is new | |
if [[ -z $isnew ]]; then | |
echo "$info" >> "${saves}" | |
notify-send "Neue Bewertung:" "$info" | |
fi | |
} | |
## login to dualis | |
cookie=$(mktemp) | |
curl -X POST --cookie ${cookie} --cookie-jar ${cookie} -s \ | |
-F "usrname=${username}" \ | |
-F "pass=${password}" \ | |
-F 'APPNAME=CampusNet' \ | |
-F 'PRGNAME=LOGINCHECK' \ | |
-F 'ARGUMENTS=clino,usrname,pass,menuno,menu_type,browser,platform' \ | |
-F 'clino=000000000000001' \ | |
-F 'menuno=000324' \ | |
-F 'menu_type=classic' \ | |
-D 'header' \ | |
"${baseurl}" > /dev/null | |
# some authentication parameters needed for dualis | |
argVar=$(sed -n 's/.*ARGUMENTS=//p' header) | |
rm header | |
curl_cmd="curl -X GET --cookie ${cookie} --cookie-jar ${cookie} -s ${baseurl}?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=" | |
## fetch semesters | |
semester=`${curl_cmd}${argVar%,*} | sed -n '/<select id="semester"/,/<\/select>/p' | grep -oP '(?<=value=").*?(?=")'` | |
## fetch links to exams | |
links="" | |
for sem in ${semester} | |
do | |
for link in `${curl_cmd}${argVar%,*},-N${sem} | grep -oP '(?<=href="/scripts/mgrqispi.dll).*RESULTDETAILS.*?(?=")'` | |
do | |
# add link to list if not already in there | |
[[ "${links}" == *"${link}"* ]] || links+=" $link" | |
done | |
done | |
# replace &-symbols in links | |
links=$(echo $links | sed 's/amp;//g') | |
## fetch exams and extract grades and course | |
for link in ${links} | |
do | |
exam=$(curl --cookie ${cookie} --cookie-jar ${cookie} -s "${baseurl}${link}") | |
grades=$(echo "$exam" | grep '^\s*[0-9]*,[0-9]') | |
i=0 | |
for grade in $grades | |
do | |
((i++)) | |
grade="${grade//[$'\t\r\n']}" | |
course=$(echo "$exam" | grep '<td class="tbdata"' | tail -$((i*4-1)) | head -1 | grep -oP '(?<=">).*(?=<)') | |
grade_fetched "$grade" "$course" | |
done | |
done | |
rm $cookie |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment