Last active
January 25, 2021 23:45
-
-
Save SoptikHa2/fe527fa0349af390ab5078ae843dab5e to your computer and use it in GitHub Desktop.
Watch KOS for teacher assignment changes and notify user
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
#!/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