Last active
August 29, 2015 14:22
-
-
Save flyinva/5930271080a895f52837 to your computer and use it in GitHub Desktop.
Un bout de shell pour savoir s'il va pleuvoir
This file contains hidden or 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
# | |
# © 2015 Flyinva | |
# https://github.com/flyinva https://twitter.com/flyinva | |
# License WTFPL | |
# | |
function get_json_cities_pluie { | |
city="$1" | |
wget --quiet --output-document=- \ | |
"http://www.meteo-france.mobi/ws/getLieux/pluie/$city.json" \ | |
| \ | |
jq --compact-output '.result[] | { id:(.indicatif | tonumber | . * 10), city: .nom}' | |
} | |
function get_json_pluie { | |
indicatif=$1 | |
wget --quiet --output-document=- \ | |
http://www.meteo-france.mobi/ws/getPluie/$indicatif.json \ | |
| \ | |
jq \ | |
--compact-output \ | |
--argfile previsions .previsions.json \ | |
'[ .result.intervalles[] | {date: (.date |tonumber) ,pluie: $previsions[.value]} ]' | |
} | |
function json_pluie_to_text { | |
# On peut passer en argument ville.json ou ville tout court | |
if [[ $1 =~ ".json" ]] | |
then | |
json="$1" | |
else | |
json="$1.json" | |
fi | |
if [ -e $json ] | |
then | |
jq --raw-output '.[] | [.date , .pluie ] | @sh' $json | while read line | |
do | |
date=${line% *} | |
date=$(( date / 1000 )) | |
date_human=$(date -d"@$date" +%H:%M) | |
prevision=${line#* } | |
prevision=${prevision//\'} | |
echo $date_human $prevision | |
done | |
else | |
echo "Pas de fichier $json" | |
return 1 | |
fi | |
} | |
function get_pluie { | |
city="$1" | |
get_json_cities_pluie "$1" | jq --raw-output '[.city, .id] | @sh' | while read line | |
do | |
city_name=${line% *} | |
city_name=${city_name//\'/} | |
city_name=${city_name,,} | |
city_id=${line#* } | |
file_name=$city_name | |
get_json_pluie $city_id > $file_name.json | |
done | |
} | |
function pluie { | |
match="$1" | |
for file in *$match* | |
do | |
echo ${file/.json} | |
json_pluie_to_text $file | |
echo | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment