-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcourses
executable file
·29 lines (22 loc) · 1.09 KB
/
mcourses
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
#!/bin/sh
# This script requires the msession script in order to receive a moodle session token
# The first argument is the user-id
echo -n "$1: "
COURSES=$(curl "https://moodle2.leibniz-gymnasium-oestringen.de/moodle/user/profile.php?id=$1&showallcourses=1" \
-H 'User-Agent: ' --silent \
-H "Cookie: MoodleSession=$(msession)" \
| grep Kursprofil | sed -E "s/<\/li><li>/\n/g;" | sed -E 's/^<a.+?course=//g;s/\&showallcourses=1\">/;/g;s/<\/a>//g;s/<.+>//g;s/\s+<a.+?course=//')
while IFS= read -r c
do
ID=$(echo $c | awk -F";" '{ print $1 }')
COURSE=$(echo $c | awk -F";" '{ print $2 }')
FACH=$(echo $COURSE | awk -F"-" '{ print $1 }' | xargs)
KLASSE=$(echo $COURSE | awk -F"-" '{ print $2 }' | xargs)
LEHRER=$(echo $COURSE | awk -F"-" '{ print $3 }' | xargs)
JAHR=$(echo $COURSE | awk -F"-" '{ print $4 }' | xargs)
echo -e "\nSchueler:$1;Kurs-ID: $ID;Fach: $FACH;Klasse: $KLASSE;Lehrer:$LEHRER;Jahr: $JAHR"
# remember the course names
doas mysql -p moodle -u root --password="" << EOF
INSERT INTO courses VALUES ($ID, "$FACH", "$KLASSE", "$LEHRER", "$JAHR");
EOF
done <<< "$COURSES"