- now fmmeteo suport 5 day forecast
- add more oprtion: (forecast, all, json)
- update documentation
This commit is contained in:
fenix-soft 2018-09-20 18:26:56 +02:00 committed by GitHub
parent 60e48f801f
commit 7bb84712a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 185 additions and 45 deletions

View File

@ -20,18 +20,36 @@ cat
fmeteo [city-name] [option]
#### option:
-f print "foorecast 5 days"
-a "all": print weather now and forecast 5 day
-j get weather information in json format
"no option" print weather now
**note:** some names of cities are made up of the aggregation of several names or terms, for some openweatermap recognizes them simply by writing them "all attacked" for others instead you have to write them separating them with the "space". In the terminal space is used to indicate the passage of further commands or options, so it is advisable to use the "% 20" character as space and enclose the name in quotation marks.
#### Some examples:
for example we want to recover the weather data of a city called "**Tempio Pausania**" (IT) or "**New York**"(USA) that openwatermap has indexed written with the space.
for example we want to recover the "now weather data" of a city called "**Tempio Pausania**" (IT) or "**New York**"(USA) that openwatermap has indexed written with the space.
fmeteo "Tempio%20Pausania,IT"
fmeteo "New%20York,US"
#### example n2:
For example I want to know the current weather and the forecast of the next 5 days of "** New York **" (USA):
fmeteo "New%20York,US" -a
or if we are a terminal that does not support xserver we can use a pager to display the data page by page:
fmeteo "New%20York,US" -a | less
use space or the arrow to go forward or back, "q" to exit
***
@ -58,14 +76,35 @@ cat
fmeteo [city-name] [option]
#### opzioni:
-f stampa a video la previsione dei 5 giorni
-a stampa il meteo corrente + la previsione dei 5 giorni
-j scarica le informazioni meteo in formato json
"nessuna opzione" stampa il meteo corrente
**nota bene:** alcuni nomi di città sono costituiti dall'aggregazione di più nomi o termini, per alcuni openweatermap li riconosce semplicemente scrivendoli "tutti attacati" per altri invece bisogna scriverli separandoli con lo "spazio". Nel terminale lo spazio serve ad indicare il passaggio di ulteriori comandi o opzioni quindi è cosigliabile utilizzare il carattere "%20" come spazio e racchiudere il nome tra virgolette.
#### Alcuni esempi:
### Alcuni esempi:
ad esempio vogliamo recuperare il tempo di una citta chiamata "**Tempio Pausania**"(IT), oppure "**New York**"(USA) che openwatermap ha indicizzato scritta con lo spazio.
ad esempio vogliamo recuperare il meteo corrente di una citta chiamata "**Tempio Pausania**"(IT), oppure "**New York**"(USA) che openwatermap ha indicizzato scritta con lo spazio.
fmeteo "Tempio%20Pausania,IT"
fmeteo "New%20York,US"
#### esempio n2:
Ad esempio voglio sapere il meteo corrente e le previsioni dei prossimi 5 giorni di "**New York**"(USA):
fmeteo "New%20York,US" -a
oppure se siamo in un terminale che non supporta xserver possiamo usare un paginatore per visualizzare i dati pagina per pagina:
fmeteo "New%20York,US" -a | less
usa spazio o le freccia per andare avanti o indietro, "q" per uscire

View File

@ -1,3 +1,7 @@
# V1.5
- now fmmeteo suport 5 day forecast
- add more oprtion: (forecast, all, json)
# V1.4
- fix conversion on wind cardinal direction, fix (deg2card V1.2)

177
fmeteo
View File

@ -4,7 +4,7 @@
####################################################################################
# script meteo che usa oopenweathermap per i dati e li riporta a terminale
#
# v:1.4
# v:1.5
#
# dipendenze: curl,jq,cat,bc
#
@ -30,58 +30,47 @@ api3="http://api.openweathermap.org/data/2.5/forecast?id="
get_Mdata(){
# get jason weather data now and extract city id
rm meteonow.txt
echo " "
echo "get data: weather now... "
curl -s $api1$surc_city$api_par$key_meteo$api_lang > meteonow.txt
echo " "
city_id=`cat meteonow.txt | jq '.list[0]|.id'`
rm meteonow.json
curl -s $api1$surc_city$api_par$key_meteo$api_lang > meteonow.json
city_id=`cat meteonow.json | jq '.list[0]|.id'`
# get jason weather data forecast general 5 day
rm meteo5.txt
echo " "
echo "get data: forecast 5 day..."
echo " "
curl -s $api2$city_id$api_par$key_meteo > meteo5.txt
rm meteo5.json
echo " "
echo "extract data file... "
echo " "
echo " "
echo " "
# dopo 5 secondi pulisco schermo
sleep 5
echo -e '\0033\0143'
curl -s $api2$city_id$api_par$key_meteo > meteo5.json
}
# exstract data to jason file
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'`
# exstract meteo data now to jason file
Meteo_now(){
city_name=`cat meteonow.json | jq -r '.list[0]|.name'`
L=`cat meteonow.json | jq -r '.list[0]|.sys[]'`
Lat=`cat meteonow.json | jq -r '.list[0]|.coord.lat'`
Lon=`cat meteonow.json | jq -r '.list[0]|.coord.lon'`
data_X=`cat meteonow.json | jq -r '.list[0]|.dt'`
data_U=`date -d @$data_X`
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'`
Wcond_n=`cat meteonow.json | jq -r '.list[0]|.weather[].main'`
Wcond_nd=`cat meteonow.json | jq -r '.list[0]|.weather[].description'`
T=`cat meteonow.json | jq -r '.list[0]|.main.temp'`
Tmax=`cat meteonow.json | jq -r '.list[0]|.main.temp_max'`
Tmin=`cat meteonow.json | jq -r '.list[0]|.main.temp_min'`
Hm=`cat meteonow.json | jq -r '.list[0]|.main.humidity'`
PrS=`cat meteonow.json | jq -r '.list[0]|.main.pressure'`
ClD=`cat meteonow.json | jq -r '.list[0]|.clouds[]'`
R=`cat meteonow.json | jq -r '.list[0]|.rain'`
S=`cat meteonow.json | jq -r '.list[0]|.snow'`
Ws=`cat meteonow.json | jq -r '.list[0]|.wind.speed'`
Wsd=`cat meteonow.json | jq -r '.list[0]|.wind.deg'`
# convert m/s to Km/s
@ -147,3 +136,111 @@ echo " "
echo " " "Wind speed (km/h): "$WsKM " " "Wind deg (°): "$Wsd " " "Wind dir: "$W_nc
echo " "
echo " "
}
# exstract forecast 5 data to jason file
forecast5() {
echo " "
echo "┌---------------------------------------------------------------┐"
echo "┊ FORECAST WEATHER 5 DAY ┊"
echo "└---------------------------------------------------------------┘"
for ((i=0; i<6; i++)); do
city_name=`cat meteonow.json | jq -r '.list[0]|.name'`
L=`cat meteonow.json | jq -r '.list[0]|.sys[]'`
Lat=`cat meteonow.json | jq -r '.list[0]|.coord.lat'`
Lon=`cat meteonow.json | jq -r '.list[0]|.coord.lon'`
data_X=`cat meteo5.json | jq -r '.list['$i']|.dt'`
data_U=`date -d @$data_X`
Wcond_n=`cat meteo5.json | jq -r '.list['$i']|.weather[].main'`
Wcond_nd=`cat meteo5.json | jq -r '.list['$i']|.weather[].description'`
Tmax=`cat meteo5.json | jq -r '.list['$i']|.temp.max'`
Tmin=`cat meteo5.json | jq -r '.list['$i']|.temp.min'`
TM=`cat meteo5.json | jq -r '.list['$i']|.temp.morn'`
TE=`cat meteo5.json | jq -r '.list['$i']|.temp.eve'`
TN=`cat meteo5.json | jq -r '.list['$i']|.temp.night'`
TD=`cat meteo5.json | jq -r '.list['$i']|.temp.day'`
Hm=`cat meteo5.json | jq -r '.list['$i']|.humidity'`
PrS=`cat meteo5.json | jq -r '.list['$i']|.pressure'`
#ClD=`cat meteo5.json | jq -r '.list['$i']|.clouds'`
R=`cat meteo5.json | jq -r '.list['$i']|.rain'`
S=`cat meteo5.json | jq -r '.list['$i']|.snow'`
Ws=`cat meteo5.json | jq -r '.list['$i']|.speed'`
Wsd=`cat meteo5.json | jq -r '.list['$i']|.deg'`
# convert m/s to Km/s
WsKM=$(echo "3.6"*$Ws | bc)
# convert degreese to cardinal name
if (($(echo "$Wsd>= 0" | bc))); then W_nc="N"; fi;
if (($(echo "$Wsd>= 11.25" | bc))); then W_nc="N-NE"; fi;
if (($(echo "$Wsd>= 33.25" | bc))); then W_nc="NE"; fi;
if (($(echo "$Wsd>= 56.25" | bc))); then W_nc="E-NE"; fi;
if (($(echo "$Wsd>= 78.75" | bc))); then W_nc="E"; fi;
if (($(echo "$Wsd>= 101.25" | bc))); then W_nc="E-SE"; fi;
if (($(echo "$Wsd>= 123.75" | bc))); then W_nc="SE"; fi;
if (($(echo "$Wsd>= 146.25" | bc))); then W_nc="S-SE"; fi;
if (($(echo "$Wsd>= 168.75" | bc))); then W_nc="S"; fi;
if (($(echo "$Wsd>= 191.25" | bc))); then W_nc="S-SW"; fi;
if (($(echo "$Wsd>= 213.75" | bc))); then W_nc="SW"; fi;
if (($(echo "$Wsd>= 236.25" | bc))); then W_nc="W-SW"; fi;
if (($(echo "$Wsd>= 258.75" | bc))); then W_nc="W"; fi;
if (($(echo "$Wsd>= 281.25" | bc))); then W_nc="W-NW"; fi;
if (($(echo "$Wsd>= 303.75" | bc))); then W_nc="NW"; fi;
if (($(echo "$Wsd>= 326.25" | bc))); then W_nc="N-NW"; fi;
if (($(echo "$Wsd>= 348.75" | bc))); then W_nc="N"; fi;
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;
# print to video all data..
echo " "
echo " "
echo " " $city_name","$L " " "Lat: "$Lat " " "Lon: "$Lon " "
echo " " "Forecast: "$data_U
echo " "
echo " " "Weather: "$Wcond_n"," $Wcond_nd
echo " "
echo " " "T.morn. (C°): "$TM " " "T.day (C°): "$TD " " "T.even. (C°): "$TE " " "T.night (C°): "$TN
echo " "
echo " " "Tmax (C°): "$Tmax" " "Tmin (C°): "$Tmin " " "Humidity (%): "$Hm
echo " "
echo " " "Pressure (hPa): "$PrS " " "Rain (mm): "$R " " "Snow (mm): "$S
echo " "
echo " " "Wind speed (km/h): "$WsKM " " "Wind deg (°): "$Wsd " " "Wind dir: "$W_nc
echo " "
done
}
if [ -z "$2" ]; then get_Mdata; Meteo_now ; fi
if [ "$2" = "-f" ]; then get_Mdata; forecast5 ; fi
if [ "$2" = "-a" ]; then get_Mdata; Meteo_now ; forecast5 ; fi
if [ "$2" = "-j" ]; then echo "get weather data.."; get_Mdata; fi

View File

@ -1 +1 @@
1.4
1.5