From c0333b8bd91b164d452e515fb4176089823aa65a Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Tue, 1 Dec 2020 12:10:20 +0530 Subject: fixed the temperature being blank if weather stat wasn't haze; currently only supports haze and smoke --- scripts/weather | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'scripts/weather') diff --git a/scripts/weather b/scripts/weather index 3fcab925..cc0ac150 100755 --- a/scripts/weather +++ b/scripts/weather @@ -1,12 +1,21 @@ #!/bin/bash get_current_temp() { - temp=$(curl wttr.in | grep °C | awk 'NR==1 {print $9 "°C"}' | sed -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g") # > /tmp/weather_temperature) - stat=$(curl wttr.in | awk 'NR==3 {print $1}') - echo $temp "("$stat")" + if [ $stat == "Smoke" ]; then + temp=$(curl wttr.in | grep °C | awk 'NR==1 {print $4 "°C"}' | sed -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g") + elif [ $stat == "Haze" ]; then + temp=$(curl wttr.in | grep °C | awk 'NR==1 {print $9 "°C"}' | sed -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g") + fi + + echo $temp +} + +get_current_weather() { + stat=$(curl wttr.in | awk 'NR==3 {print $1}') + echo $(get_current_temp) "("$stat")" } while :; do - echo $(get_current_temp) > /tmp/weather_stat + echo $(get_current_weather) > /tmp/weather_stat sleep 3600 done -- cgit v1.2.3