Last active
July 20, 2016 20:43
-
-
Save libetl/94092796d225aec9de73c7f41f9e58bb to your computer and use it in GitHub Desktop.
free-reseau-incidents-du-jour.sh
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 | |
ESC=$(printf '\033'); | |
RESULT="$(curl -s https://www.free-reseau.fr/incidents-du-jour/)" | |
echo -e " \033[1;33mNRA\033[0m \033[1;36m0h 4h 8h 12h 16h 20h\033[0m"; | |
echo "$RESULT" | xmllint --html --nowarning --xpath '/html/body/table[position()>2]' - 2>/dev/null | tr '\n' ' ' | sed 's/\s\+/ /g' | sed 's/>\s\+</></g' | sed 's/\(<\/table>\)\?<table style="width:98%; padding-bottom:5px; padding-right:5px;" class="general"><colgroup style="width:22%"><\/colgroup><colgroup class="tablo_group" span="48"><\/colgroup><tr><td> <\/td><td colspan="8">2h<\/td><td colspan="8">6h<\/td><td colspan="8">10h<\/td><td colspan="8">14h<\/td><td colspan="8">18h<\/td><td colspan="8">22h<\/td><\/tr>//g' | sed 's/<tr><td colspan="49"><\/td><\/tr>//g' | sed 's/<\/table><table style="margin-left:auto; margin-right:auto;">.*//' | sed 's/<td class="etatok">1<\/td>/./g' | sed 's/<td class="etatnok">X<\/td>/X/g' | sed 's/<td class="etatnonfait"><\/td>/-/g' | sed 's/<tr><td style="width:300px;"><div class="text_tablo"><a id="[^"]\+"><\/a><a href="..\/[^"]\+">\([^<]\+\)<\/a> - (<i>\([^<]\+\)<\/i>)<\/div><\/td>/\1 \2:/g' | sed 's/<\/tr>/\n/g' | sed "s,\.,${ESC}[42m\-${ESC}[0m,g" | sed "s,X,${ESC}[41m-${ESC}[0m,g" | grep -v '\<table\>' | while read LINE;do LOCATION="$(echo "$LINE" | cut -d':' -f1 | tr -d '\200-\377')";STATUS="$(echo "$LINE" | cut -d':' -f2)";printf "\033[1;33m%+60s\033[0m %s\n" "$LOCATION" $STATUS;done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment