commit e974f6911e2f9fe5e099895c50dcd4479c78534f
parent 49f7574a9b6797399b9ea66c9479aed385bb3933
Author: Frederic Cambus <fred@statdns.com>
Date: Fri, 29 Jun 2018 12:12:19 +0200
Add support for fetching and displaying UV index
Diffstat:
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/ansiweather b/ansiweather
@@ -44,7 +44,7 @@ fetch_cmd=$(get_config "fetch_cmd" || echo "curl -sf")
###[ Parse the command line ]##################################################
# Get config options from command line flags
-while getopts l:u:f:Fa:s:k:w:h:p:d:v option
+while getopts l:u:f:Fa:s:k:i:w:h:p:d:v option
do
case "${option}"
in
@@ -55,6 +55,7 @@ do
a) ansi=${OPTARG};;
s) symbols=${OPTARG};;
k) api_key=${OPTARG};;
+ i) show_uvi=${OPTARG};;
w) show_wind=${OPTARG};;
h) show_humidity=${OPTARG};;
p) show_pressure=${OPTARG};;
@@ -104,6 +105,9 @@ fi
# Display symbols: "true" or "false" (requires a Unicode capable display)
[ -z "$symbols" ] && symbols=$(get_config "symbols" || echo false)
+# Show UVI: "true" or "false"
+[ -z "$show_uvi" ] && show_uvi=$(get_config "show_uvi" || echo true)
+
# Show wind: "true" or "false"
[ -z "$show_wind" ] && show_wind=$(get_config "show_wind" || echo true)
@@ -187,6 +191,19 @@ fi
+###[ Fetch UV data ]###########################################################
+
+if [ "$show_uvi" = true ]
+then
+ lat=$(echo "$weather" | jq -r '.coord.lat')
+ lon=$(echo "$weather" | jq -r '.coord.lon')
+
+ uvdata=$($fetch_cmd "http://api.openweathermap.org/data/2.5/uvi?lat=$lat&lon=$lon&appid=$api_key")
+ uvi=$(echo "$uvdata" | jq -r '.value')
+fi
+
+
+
###[ Process Weather data ]####################################################
epoch_to_date() {
@@ -376,6 +393,11 @@ else
fi
output="$background$text $greeting_text $city $delimiter$data $temperature $scale $icon"
+ if [ "$show_uvi" = true ]
+ then
+ output="$output$dashes$text UVI $delimiter$data $uvi "
+ fi
+
if [ "$show_wind" = true ]
then
output="$output$dashes$text $wind_text $delimiter$data $wind $speed_unit $direction "