fmeteo/fmeteo

150 lines
3.9 KiB
Plaintext
Raw Normal View History

2018-09-11 11:18:34 +02:00
#!/bin/bash
#
#
####################################################################################
2018-09-11 12:09:23 +02:00
# script meteo che usa oopenweathermap per i dati e li riporta a terminale
2018-09-11 11:18:34 +02:00
#
# v:1.4
2018-09-11 11:18:34 +02:00
#
# dipendenze: curl,jq,cat,bc
#
#
####################################################################################
2018-09-11 12:09:23 +02:00
# set api-key
key_meteo="1487dd8a93bfd85d278d9ac8dcfee94c"
2018-09-11 11:18:34 +02:00
# set global variable
surc_city=$1
api1="http://api.openweathermap.org/data/2.5/find?q="
api_par="&units=metric&appid="
api_lang="&lang=en"
api2="http://api.openweathermap.org/data/2.5/forecast/daily?id="
api3="http://api.openweathermap.org/data/2.5/forecast?id="
2018-09-11 12:09:23 +02:00
2018-09-11 11:18:34 +02:00
# get jason weather data now and extract city id
rm meteonow.txt
echo " "
2018-09-11 13:44:05 +02:00
echo "get data: weather now... "
curl -s $api1$surc_city$api_par$key_meteo$api_lang > meteonow.txt
2018-09-11 11:18:34 +02:00
echo " "
2018-09-11 12:09:23 +02:00
city_id=`cat meteonow.txt | jq '.list[0]|.id'`
2018-09-11 11:18:34 +02:00
# get jason weather data forecast general 5 day
rm meteo5.txt
echo " "
2018-09-11 13:44:05 +02:00
echo "get data: forecast 5 day..."
2018-09-11 11:18:34 +02:00
echo " "
2018-09-11 13:44:05 +02:00
curl -s $api2$city_id$api_par$key_meteo > meteo5.txt
2018-09-11 11:18:34 +02:00
echo " "
2018-09-11 13:44:05 +02:00
echo "extract data file... "
2018-09-11 11:18:34 +02:00
echo " "
echo " "
echo " "
# dopo 5 secondi pulisco schermo
sleep 5
echo -e '\0033\0143'
# exstract data to jason file
2018-09-11 12:09:23 +02:00
city_name=`cat meteonow.txt | jq -r '.list[0]|.name'`
L=`cat meteonow.txt | jq -r '.list[0]|.sys[]'`
Lat=`cat meteonow.txt | jq -r '.list[0]|.coord.lat'`
Lon=`cat meteonow.txt | jq -r '.list[0]|.coord.lon'`
data_X=`cat meteonow.txt | jq -r '.list[0]|.dt'`
2018-09-11 11:18:34 +02:00
data_U=`date -d @$data_X`
2018-09-11 12:09:23 +02:00
Wcond_n=`cat meteonow.txt | jq -r '.list[0]|.weather[].main'`
Wcond_nd=`cat meteonow.txt | jq -r '.list[0]|.weather[].description'`
T=`cat meteonow.txt | jq -r '.list[0]|.main.temp'`
Tmax=`cat meteonow.txt | jq -r '.list[0]|.main.temp_max'`
Tmin=`cat meteonow.txt | jq -r '.list[0]|.main.temp_min'`
Hm=`cat meteonow.txt | jq -r '.list[0]|.main.humidity'`
PrS=`cat meteonow.txt | jq -r '.list[0]|.main.pressure'`
ClD=`cat meteonow.txt | jq -r '.list[0]|.clouds[]'`
R=`cat meteonow.txt | jq -r '.list[0]|.rain'`
S=`cat meteonow.txt | jq -r '.list[0]|.snow'`
Ws=`cat meteonow.txt | jq -r '.list[0]|.wind.speed'`
Wsd=`cat meteonow.txt | jq -r '.list[0]|.wind.deg'`
2018-09-11 11:18:34 +02:00
2018-09-12 17:12:13 +02:00
2018-09-11 11:18:34 +02:00
# convert m/s to Km/s
WsKM=$(echo "3.6"*$Ws | bc)
2018-09-12 17:12:13 +02:00
# convert degreese to cardinal name
if (($(echo "$Wsd>= 0" | bc))); then W_nc="N"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 11.25" | bc))); then W_nc="N-NE"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 33.25" | bc))); then W_nc="NE"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 56.25" | bc))); then W_nc="E-NE"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 78.75" | bc))); then W_nc="E"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 101.25" | bc))); then W_nc="E-SE"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 123.75" | bc))); then W_nc="SE"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 146.25" | bc))); then W_nc="S-SE"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 168.75" | bc))); then W_nc="S"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 191.25" | bc))); then W_nc="S-SW"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 213.75" | bc))); then W_nc="SW"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 236.25" | bc))); then W_nc="W-SW"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 258.75" | bc))); then W_nc="W"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 281.25" | bc))); then W_nc="W-NW"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 303.75" | bc))); then W_nc="NW"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 326.25" | bc))); then W_nc="N-NW"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd>= 348.75" | bc))); then W_nc="N"; fi;
2018-09-12 17:12:13 +02:00
if (($(echo "$Wsd> 360" | bc))); then W_nc="-?-"; fi;
if (($(echo "$Wsd< 0" | bc))); then W_nc="-?-"; fi
if [ "$Wsd" = "null" ]; then W_nc="-?-"; fi;
2018-09-12 17:12:13 +02:00
2018-09-11 11:18:34 +02:00
# print to video all data..
echo " "
2018-09-11 12:09:23 +02:00
echo " " $city_name","$L " " "Lat: "$Lat " " "Lon: "$Lon " " "id:" $city_id
2018-09-11 11:18:34 +02:00
echo " " $data_U
echo " "
echo " " "Weather: "$Wcond_n"," $Wcond_nd
echo " "
2018-09-11 12:09:23 +02:00
echo " " "Temp (C°): "$T " " "Tmax (C°): "$Tmax" " "Tmin (C°): "$Tmin " " "Humidity (%): "$Hm
echo " "
echo " " "Pressure (hPa): "$PrS " " "Clouds (%): "$ClD " " "Rain (mm): "$R " " "Snow (mm): "$S
echo " "
2018-09-12 17:12:13 +02:00
echo " " "Wind speed (km/h): "$WsKM " " "Wind deg (°): "$Wsd " " "Wind dir: "$W_nc
2018-09-11 11:18:34 +02:00
echo " "
echo " "