Tips & Trick: piccolo script per le previsioni meteo da terminale
Vi posto un piccolo script, trovato su internet, che ci permette di vedere le previsioni meteo direttamente da terminale (una vera goduria per gli amanti del terminale
).
Bene dopo aver creato un file da nome “.weather-script.sh”, apritelo con un editor qualsiasi e aggiungeteci questo: #!/bin/bash
read paese
echo; echo; echo; echo; echo
wget "http://www.google.com/ig/api?weather=$paese,italy&hl=it" 2>/dev/null -O -| tr '>' '\n' | tr '/' ' ' | tr '"' ' ' | tr '<' ' ' >filetmp.txt
echo "=========================================="
echo "IL TEMPO SU :" $(cat filetmp.txt | grep city | cut -d'=' -f2)
echo "=========================================="
echo "Condizione attuale :" $(cat filetmp.txt | head -n 14 | tail -n 1 | cut -d'=' -f2)
echo "Data odierna :" $(cat filetmp.txt | grep forecast_date | cut -d'=' -f2)
echo "Temperatura attuale:" $(cat filetmp.txt | grep temp_c | cut -d'=' -f2) "gradi Celsius"
echo "Umidita' :" $(cat filetmp.txt | grep humidity | cut -d':' -f2)
echo "Vento :" $(cat filetmp.txt | grep wind_condition | cut -d':' -f2)
echo
echo "=========================================="
echo "* PREVISIONI per i PROSSIMI GIORNI *"
echo "=========================================="
echo "Giorno :" $(cat filetmp.txt | head -n 22 | tail -n 1 | cut -d'=' -f2)
echo "Temperatura minima :" $(cat filetmp.txt | head -n 23 | tail -n 1 | cut -d'=' -f2)
echo "Temperatura massima:" $(cat filetmp.txt | head -n 24 | tail -n 1 | cut -d'=' -f2)
echo "Condizione :" $(cat filetmp.txt | head -n 26 | tail -n 1 | cut -d'=' -f2)
echo "------------------------------------------"
echo "Giorno :" $(cat filetmp.txt | head -n 29 | tail -n 1 | cut -d'=' -f2)
echo "Temperatura minima :" $(cat filetmp.txt | head -n 30 | tail -n 1 | cut -d'=' -f2)
echo "Temperatura massima:" $(cat filetmp.txt | head -n 31 | tail -n 1 | cut -d'=' -f2)
echo "Condizione :" $(cat filetmp.txt | head -n 33 | tail -n 1 | cut -d'=' -f2)
echo "------------------------------------------"
echo "Giorno :" $(cat filetmp.txt | head -n 36 | tail -n 1 | cut -d'=' -f2)
echo "Temperatura minima :" $(cat filetmp.txt | head -n 37 | tail -n 1 | cut -d'=' -f2)
echo "Temperatura massima:" $(cat filetmp.txt | head -n 38 | tail -n 1 | cut -d'=' -f2)
echo "Condizione :" $(cat filetmp.txt | head -n 40 | tail -n 1 | cut -d'=' -f2)
echo "------------------------------------------"
echo "Giorno :" $(cat filetmp.txt | head -n 43 | tail -n 1 | cut -d'=' -f2)
echo "Temperatura minima :" $(cat filetmp.txt | head -n 44 | tail -n 1 | cut -d'=' -f2)
echo "Temperatura massima:" $(cat filetmp.txt | head -n 45 | tail -n 1 | cut -d'=' -f2)
echo "Condizione :" $(cat filetmp.txt | head -n 47 | tail -n 1 | cut -d'=' -f2)
echo "=========================================="
echo
fatto questo per vedere le previsioni meteo vi basterà scrivere da terminale ./.weather-script.sh paese, dove al posto di “paese” mettete il paese che vi interessa.
Un consiglio?!? aprite il file .bashrc e aggiungete il seguente alias: alias meteo='./.weather-script.sh', così per avviarlo vi basterà meteo paese

