Skip to content

Instantly share code, notes, and snippets.

@blegat
Forked from GuillaumeDerval/verifier.sh
Last active August 29, 2015 14:02
Show Gist options
  • Save blegat/5f524b2a2af0a330066a to your computer and use it in GitHub Desktop.
Save blegat/5f524b2a2af0a330066a to your computer and use it in GitHub Desktop.
#!/bin/bash
# UCL Virtual Desktop Update Checker (VDUC pour les intimes)
# Averti quand votre bureau virtuel est mit à jour
# Guillaume Derval
# GPLv3
uclID="IDENTIFIANT UCL" #Identifiant global UCL
uclPASS='PASS UCL' #Le pass UCL. sisi.
activateBell=1 #Son en boucle si MAJ
# Add sounds here in first if you want it to be played
# Only the first sound that exists is played
sounds=('/usr/share/sounds/freedesktop/stereo/complete.oga' '/usr/share/sounds/ubuntu/notifications/Mallet.ogg' '/usr/share/sounds/gnome/default/alerts/glass.ogg' '/usr/share/sounds/KDE-Im-Nudge.ogg' '/usr/share/sounds/freedesktop/stereo/bell.oga')
macosx=0
if [[ "$OSTYPE" == "darwin"* ]]; then
macosx=1
fi
rm *.html
BASEIFS=$IFS
points=( )
while [ 0 ]
do
#Re-affichons le status a l'ecran
clear
for i in "${points[@]}"
do
echo 'Numero $i modifie! Consultez last.$i.html!'
done
#On se deconnecte (oubli du cookie) et on se reconnecte
echo 'Connexion'
if [[ -e "cookie" ]]
then
rm cookie
fi
curl -s --request POST 'https://www.uclouvain.be/page_login.html' --data "username=$uclID&password=$uclPASS" -c cookie > log.html
sleep 5
echo 'Verification'
curl -s --request POST 'https://www.uclouvain.be/index.html' --data '' -c cookie -b cookie > index.html
sleep 5
#Si la page d'acceuil affiche "se deconnecter" alors on est bien connecte
if [ `cat index.html | grep 'page_logout' | wc -l` -ge 1 ]
then
rm log.html
rm index.html
#On va sur le bureau, et on prend toutes les annees (on ne sais jamais :D)
echo 'Recuperation des etudes'
curl -s --request POST 'http://www.uclouvain.be/onglet_etudes.html' --data '' -c cookie -b cookie > etudes.html
sleep 5
etudes=( `cat etudes.html | grep 'onglet_etudes.html?cmp=cmp_formations.html&fct=notes&numOffre=' | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | sort | uniq` )
for i in "${etudes[@]}"
do
#On va chercher la page associee a l'annee
i=${i//"&"/"&"}; #remplacement des & en &
j=`echo $i | grep -o -E 'numOffre=([0-9]+)' | cut -d'=' -f2`
k=`echo $i | grep -o -E 'anac=([0-9]+)' | cut -d'=' -f2`
file="$j_$k.html"
echo "Recuperation de $j de $k"
curl -s --request POST "http://www.uclouvain.be/$i" --data '' -c cookie -b cookie > $file
if [[ $? == 0 ]]
then
sleep 5
#Tout ca extrait le tableau des points
lbegin=`cat $file | grep -o -E '<td class="composant-titre-inter">Cours</td>' -n | cut -d':' -f1`
(( lbegin-- ))
IFS=$'\n'
index=0
while read line; do
fichier[index]="$line"
(( index++ ))
done < $file
IFS=$BASEIFS
tableau="<table>"
step=1
while [ "$step" -lt "2" ]
do
tableau="$tableau ${fichier[lbegin]}"
if [[ "${fichier[lbegin]}" == "</table>" ]]
then
(( step++ ))
fi
if [[ "${fichier[lbegin]}" == \<table* ]]
then
(( step-- ))
fi
(( lbegin++ ))
done
echo $tableau > "tab.$file"
#Maintenant qu'on a le tableau, on aimerai savoir si ca c'est ameliore
if [[ -e "last.$file" && `cat "last.$file"` != `cat "tab.$file"` ]]
then
if [[ ${points[*]} =~ "$j" ]]
then
echo "$j de $k verifie, MODIFIE!"
else
points=( ${points[@]} $j )
echo "$j de $k verifie, MODIFIE!"
fi
if [[ "$activateBell" = "1" ]]
then
#macosx
audio=/System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/BackThrough.aiff
while [ 0 ]
do
if [[ "$macosx" = "1" ]]
then
afplay $audio
else
for sound in "${sounds[@]}"
do
if [ -e $sound ]
then
paplay $sound
break
fi
done
sleep 1 # Ctrl+C kills paplay and not this script if it is running
# Ctrl+C during the sleep works, that is the use of this sleep
fi
done
fi
else
echo "$j de $k verifie, pas de modification"
fi
#Maj
if [[ -e "last.$file" ]]
then
rm "last.$file"
fi
mv "tab.$file" "last.$file"
else
echo "erreur lors du chargement de $j de $k"
fi
done
else
echo 'Erreur, vous avez probablement oublier de changer votre PASS et ID dans ce script'
fi
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment