-
Notifications
You must be signed in to change notification settings - Fork 0
/
NOTEN.sh
executable file
·241 lines (206 loc) · 5.8 KB
/
NOTEN.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/bash
while ! mkdir ./.lock 2>/dev/null
do
sleep 1
done
trap "rm -rf ./.lock; exit" INT TERM EXIT
while getopts hju:p: opt
do
case $opt in
u) username=$OPTARG;;
p) password=$OPTARG;;
h) echo
echo "Call:"
echo " ./NOTEN.sh [Options]"
echo
echo "Options:"
echo -e " -u\tSet username"
echo -e " -p\tSet password"
echo
echo "For more details see https://github.com/neinkob15/DualisApp"
exit 0;;
esac
done
if [ -z "${username}" ]
then
echo "Username cannot be empty"
exit 1
fi
if [ -z "${password}" ]
then
echo "Password cannot be empty"
exit 1
fi
curl -X POST -c "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' \
"https://dualis.dhbw.de/scripts/mgrqispi.dll" > /dev/null
argVar=$(sed -n 's/.*ARGUMENTS=//p' header)
url="https://dualis.dhbw.de/scripts/mgrqispi.dll?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=${argVar}"
url=${url%$'\r'}
curl -X GET -b ./cookie -s "${url}" > page.html
lines=$(sed -n '/<select id="semester"/,/<\/select>/p' page.html)
# Semester numbers
arrNum=()
# Semester String
arrSem=()
i=0
#echo "SEMESTER:"
IFS=$'\n'
for line in $lines
do
line=$(echo $line | tr -d "\t")
line=$(echo $line | grep "option")
if ! [ -z "${line}" ]; then
arrNum[i]=$(echo $line | sed 's/.*value=\"\(.*\)\" .*/\1/')
arrSem[i]=$(echo $line | sed 's/.*>\(.*\)<\/option>.*/\1/')
# echo "$((i+1))| ${arrSem[i]}"
i=$((i+1))
fi
done
l=$i
now=$(date)
echo "["
# loop through semesters
for (( m=0; m<$l; m++ ))
do
semester=$m
echo " {"
echo " \"semester\":\"${arrSem[semester]}\","
echo " \"modules\": ["
arg1=$(echo $argVar | cut -d"," -f1)
arg2=$(echo $argVar | cut -d"," -f2)
url2="https://dualis.dhbw.de/scripts/mgrqispi.dll?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=$arg1,$arg2,-N${arrNum[semester]}"
curl -b ./cookie -s $url2 > page.html
lines=$(sed -n '/.*<tbody>/,/.*<\/tbody>/p' page.html)
lines=$(echo "$lines" | sed -e 's/^[[:space:]]*//' | sed -e '/^$/d' | grep 'td.*"tbdata".*td\|href="/script')
arrModules=()
arrLinks=()
i=0
j=0
k=0
for line in $lines
do
if [[ $line == *"tbdata"* ]]; then
if ((i % 2)); then
arrModules[j]=$(echo $line | sed 's/.*>\(.*\)<.*/\1/')
# echo "$((j+1))| ${arrModules[j]}"
j=$((j+1))
fi
i=$((i+1))
else
arrLinks[k]=$(echo $line | sed 's/.*href="\(.*\)".*/\1/' | sed 's/\&/\&/g')
arrLinks[k]=$(echo "https://dualis.dhbw.de${arrLinks[k]}")
k=$((k+1))
fi
done
# loop through modules
for (( c=0; c<$k; c++ ))
do
module=$c
echo " {"
echo " \"name\":\"${arrModules[c]}\","
echo " \"exams\": ["
curl -b ./cookie -s "${arrLinks[module]}" > page.html
lines=$(sed -n '/Versuch/,/Bausteine/p' page.html)
# if ! [ -z "{$lines}" ]; then
# echo $lines > bug.txt
# bug3=1
# fi
flag=0
flag2=0
flag3=0
lineCount=0
examName=""
for line in $lines
do
if [[ $line == *" "* ]] || [[ $line == *"tbdata\" >"* ]] || [[ $line == *"colspan=\"8\""* ]]; then
#if #tbdata ># and next lines no then...
check1=$(echo "$lines" | grep -A20 $line)
check2=$(echo "$lines" | grep -A5 $line)
# echo "$check1"
if [[ $line == *"tbdata\" >"* ]] && ! [[ "$check1" == *" "* ]] || [[ $line == *" "* ]] || [[ $line == *"colspan=\"8\""* ]]; then
oldLine=$(echo $line)
line=$(echo "$line" | sed 's/.*>\(.*\)<.*/\1/' | sed 's/ //g')
if ! [[ $line == *"<td class"* ]]; then
if [[ "$check2" == *","* ]] || [[ "$check2" == *"noch nicht gesetzt"* ]] || [[ "$check2" == *" b"* ]] || [[ $oldLine == *"colspan=\"8\""* ]]; then
if ! [[ $line == *"Modulabschlussleistungen"* ]]; then
if [[ "$oldLine" == *"colspan=\"8\""* ]]; then
# echo "Name: $line"
examName=$(echo $line | cut -d " " -f3- )
else
if ! [ $flag2 -eq 0 ]; then
echo " },"
echo " {"
else
echo " {"
fi
if [ -z $examName ]; then
echo " \"exam\":\"$line\","
flag3=1
else
percent=$(echo $line | cut -d "(" -f2 | cut -d ")" -f1 )
echo " \"exam\":\"$examName ($percent)\","
flag3=1
fi
lineCount=$((lineCount+1))
fi
fi
fi
fi
fi
if [[ "$check1" == *" "* ]] && [[ $line == *"tbdata\" >"* ]] && { [[ "$check2" == *","* ]] || [[ "$check2" == *"noch nicht gesetzt"* ]] || [[ "$check2" == *" b"* ]]; } ; then
flag=1
fi
fi
if [[ $line =~ [0-9]+,[0-9]+ ]] || [[ $line == *"noch nicht gesetzt"* ]] || [[ $line == *" b"* ]]; then
if [ $flag -eq 1 ]; then
flag=0
else
if ! [[ $line == *"bestanden"* ]] && ! [[ $line == *"\"noch"* ]] && ! [[ $line == *"<div"* ]]; then
if [[ $line == *"<td"* ]]; then
grade=$(echo "$line" | sed 's/.*>\(.*\)<.*/\1/')
grade=$(echo $grade | sed 's/\r//g' )
grade=$(echo $grade | sed 's/ //g' )
if ! [[ $grade == *")"* ]]; then
echo " \"grade\":\"$grade\""
flag2=1
fi
else
grade=$(echo "$line" | sed 's/^ *//g' | sed 's/noch nicht gesetzt/-/g')
grade=$(echo $grade | sed 's/\r//g' )
grade=$(echo $grade | sed 's/ //g' )
if ! [[ $grade == *")"* ]]; then
echo " \"grade\":\"$grade\""
flag2=1
fi
fi
fi
fi
fi
done
if ! [ $flag3 -eq 0 ];then
echo " }"
fi
echo " ]"
if [ $c -eq $((k-1)) ]; then
echo " }"
else
echo " },"
fi
done
echo " ]"
if [ $m -eq $((l-1)) ]; then
echo " }"
else
echo " },"
fi
done
echo "]"