|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# This script parses SIS for a CSV file of a specific room and saves it
|
|
|
|
# in the working directory. The correct room ID is parsed first followed
|
|
|
|
# by a given CSV file.
|
|
|
|
|
|
|
|
# The hostname of the computer running this script has to have the name
|
|
|
|
# of a corresponding room after the first hyphen, eg. "rzv-r013h",
|
|
|
|
# where the room name would be "R013H" as defined in SIS.
|
|
|
|
|
|
|
|
# Curl with TLS support needs to be installed as well as iconv for
|
|
|
|
# Windows-1250 to UTF-8 encoding conversion.
|
|
|
|
|
|
|
|
# All utilities used: curl, sed, grep, tr, iconv
|
|
|
|
|
|
|
|
#ROOM_NAME=$(hostname | sed "s/.*-//" | tr "[:lower:]" "[:upper:]")
|
|
|
|
ROOM_NAME=$(echo rzv-r013h | sed "s/.*-//" | tr "[:lower:]" "[:upper:]")
|
|
|
|
ROOM_ID=$(curl -s "https://is.cuni.cz/studium/rozvrhng/roz_ucebna_macro.php?skr=2018&sem=2&fak=11410" | sed "s,</a>,\n,g" | grep $ROOM_NAME | grep -oP "ucebna=\K[^ ]+" | tr -d "\"")
|
|
|
|
|
|
|
|
printf "%s\n" "Fetching room $ROOM_NAME with ID $ROOM_ID"
|
|
|
|
curl -s "https://is.cuni.cz/studium/rozvrhng/roz_ucebna_micro.php?ucebna=$ROOM_ID&fak=11410&csv=1" > $ROOM_NAME.csv
|
|
|
|
iconv -f WINDOWS-1250 -t UTF-8 $ROOM_NAME.csv -o $ROOM_NAME.csv
|
|
|
|
|
|
|
|
|
|
|
|
DATE=$(date -d "tomorrow" "+%-d.%-m.%Y" )
|
|
|
|
FILE="$ROOM_NAME"".csv"
|
|
|
|
TODAY=$(grep "$DATE" "$FILE")
|
|
|
|
|
|
|
|
echo "$TODAY"
|
|
|
|
while read line
|
|
|
|
do
|
|
|
|
|
|
|
|
LECTURE=$(echo $line | cut -d';' -f 4)
|
|
|
|
START=$(date -d "today 0 +$(echo $line | cut -d';' -f 7) minutes" "+%T")
|
|
|
|
DURRATION=$(echo $line | cut -d';' -f 9)
|
|
|
|
END=$(date -d "$START $DURRATION minutes" "+%T")
|
|
|
|
TEACHER=$(echo $line | cut -d';' -f 10)
|
|
|
|
|
|
|
|
echo "$LECTURE; $START; $END; $TEACHER"
|
|
|
|
|
|
|
|
done <<< "$TODAY"
|