Skip to content

Instantly share code, notes, and snippets.

@frafra
Created November 28, 2013 21:10
Show Gist options
  • Save frafra/7698152 to your computer and use it in GitHub Desktop.
Save frafra/7698152 to your computer and use it in GitHub Desktop.
Mostra lo stato delle stazioni per le biciclette di Savona
#!/bin/bash
SAVONA='http://www.bicincitta.com/citta_v3.asp?id=43&pag=2'
NAME="bici-in-città"
temp=$(mktemp --suffix=$NAME)
curl -s $SAVONA -o $temp
code=$(grep 'var sita_n' $temp | cut -d\" -f2,4 --output-delimiter=)
IFS=$'_' places=($code)
code=$(grep 'var sita_b' $temp | cut -d= -f2 | tr -cd [04_])
IFS=$'_' status=($code)
rm $temp
for ((i=0;i<${#places[@]};i++)); do
available=$(echo ${status[$i]} | tr -cd 4 | wc -m)
busy=$(echo ${status[$i]} | tr -cd 0 | wc -m)
total=$(($available+$busy))
echo ${places[$i]} $available/$total | recode html..utf-8
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment