Skip to content

Instantly share code, notes, and snippets.

@SoptikHa2
Last active January 25, 2021 23:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SoptikHa2/fe527fa0349af390ab5078ae843dab5e to your computer and use it in GitHub Desktop.
Save SoptikHa2/fe527fa0349af390ab5078ae843dab5e to your computer and use it in GitHub Desktop.
Watch KOS for teacher assignment changes and notify user
#!/usr/bin/env bash
declare -A subject_teachers
#┌───────┐
#│ SETUP │
#└───────┘
# 1. Install chromedriver
# 2. Make sure notify-send properly sends notifications
# 3. (Optional) Install espeak-ng and voice bank for voice warning
# 4. git clone https://github.com/Rasukarusan/shellnium
# 5. Place this file in the cloned folder
# 6. Change configuration and run
# ┌───────────────┐
# │ CONFIGURATION │
# └───────────────┘
username="FIT_USERNAME"
password="FIT_PASSWORD"
subjects="BI-PA2 BI-LIN"
subject_teachers[BI-PA2]="Matoušek Bernhauer Kříž"
subject_teachers[BI-LIN]="Dombek"
#┌──────────────────────┐
#│ END OF CONFIGURATION │
#└──────────────────────┘
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
( chromedriver & ) || ( echo "Failed to start chromedriver. Is it installed?" >&2; exit 1 )
source $HOME/data/Applications/shellnium/lib/selenium.sh
login () {
navigate_to 'https://www.kos.cvut.cz/'
local usernameBox=$(find_element 'id' 'userName')
local passwordBox=$(find_element 'id' 'password')
local loginButton=$(find_element 'name' 'vstup')
send_keys "$usernameBox" "$username"
send_keys "$passwordBox" "$password"
click "$loginButton"
}
navigateToTimetable () {
exec_script "javascript:window.open('ttAllsubjects.do?page='+pageCode,'_self')"
}
navigateToSubject () {
echo "Navigate to subject $1"
local link_subject=$(find_element 'xpath' "//a[contains(@href, '$1') and contains(text(), 'Zobrazit')]")
click "$link_subject"
}
checkTeacher () {
printf "\tCheck teacher %s\n" "$1"
local teacher=$(find_element 'xpath' "//a[contains(text(), '$1')]")
if [[ "$teacher" != "null" ]]; then
for i in $(seq 1 10); do
notify-send "TEACHER FOUND: $1"
espeak-ng "Teacher found. $1" -a 150 || true
sleep 1;
done
fi
}
login
while true; do
for subject in $subjects; do
navigateToTimetable
teachers=${subject_teachers[$subject]}
navigateToSubject "$subject"
for teacher in $teachers; do
checkTeacher "$teacher"
done
done
echo "Sleep 14 minutes"
sleep $((14*60))
done
delete_session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment