Last active
January 4, 2016 06:19
-
-
Save GuillaumeDerval/8581278 to your computer and use it in GitHub Desktop.
Averti quand votre bureau virtuel est mit à jour
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
#!/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 | |
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` | |
file="$j.html" | |
echo "Recuperation de $j" | |
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 verifie, MODIFIE!" | |
else | |
points=( ${points[@]} $j ) | |
echo "$j 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 | |
printf "\a\a\a\a\a\a\a\a" | |
sleep 1 | |
fi | |
done | |
fi | |
else | |
echo "$j 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" | |
fi | |
done | |
else | |
echo 'Erreur' | |
fi | |
sleep 60 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment