Bash weather forecast script and conky config

This is the revised version of the femeteo script I created.

#!/bin/bash
#
#
####################################################################################
# script meteo che usa  oopenweathermap per i dati e li riporta a terminale
#
# v:1.5
#
# dipendenze: curl,jq,cat,bc
#
#
####################################################################################



# set api-key

key_meteo="1487dd8a93bfd85d278d9ac8dcfee94c"



# 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="



get_Mdata(){

# get jason weather data now and extract city 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.json

curl -s $api2$city_id$api_par$key_meteo > meteo5.json
}



# 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.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'`
Icon=`cat meteonow.json | jq -r '.list[0]|.weather[].icon'`
URL=http://openweathermap.org/img/w/$Icon.png
wget -O /home/pi/icon.png $URL

# 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 $Wcond_nd " "$T"C° "$ClD"%"
echo "Rn:"$R "Sn:"$S "Wd:"$WsKM "Dr:"$W_nc
}



# exstract forecast 5 data to jason file
forecast5() {

for ((i=0; i<2; 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'`
Iconf=`cat meteonow.json | jq -r '.list['$i']|.weather[].icon'`
URL=http://openweathermap.org/img/w/$Iconf.png
wget -O /home/pi/iconf$i.png $URL


# 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 $data_U " "$Wcond_nd
echo "M:"$TM  " " "D:"$TD  " "  "E:"$TE  " " "N:"$TN
echo "Rn:"$R " " "Sn:"$S " " "Wd:"$WsKM " " "Dr:"$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

And this is the conky config I created to display the forecast:

background yes
use_xft yes
xftfont 123:size=13
xftalpha 0.1
update_interval 1
total_run_times 0
own_window yes
own_window_type normal
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 320
maximum_width 320
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
default_color gray
default_shade_color red
default_outline_color green
alignment top_left
gap_x 1
gap_y 1
no_buffers no
uppercase no
cpu_avg_samples 2
net_avg_samples 1
override_utf8_locale yes
use_spacer right
text_buffer_size 512

TEXT
${font Arial:bold:size=45}${color #8b0000}${time %T}${font Arial:size=10}${font}
${font Arial:size=8}${color #8b0000}${time %a} ${font Arial:size=8}${color #8b0000}${time %d %B %Y}${font}
${image /home/pi/icon.png -p 250,50 -s 55x55}${font Arial:size=20}${color #8b0000}${execi 1800 cat /home/pi/wttrn}
${image /home/pi/iconf0.png -p 250,150 -s 55x55}${font Arial:size=10}${color #8b0000}${execi 1800 cat /home/pi/wttrf}