From f5c0789d0783f1de1472c251b6eaccfb99f97525 Mon Sep 17 00:00:00 2001 From: yzenati <9922120+yzenati@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:56:41 +0200 Subject: [PATCH 1/6] Add an option to disable the location information in the weather --- scripts/dracula.sh | 3 ++- scripts/sleep_weather.sh | 3 ++- scripts/weather.sh | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 7a67e58..d25e57b 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -21,6 +21,7 @@ main() show_network=$(get_tmux_option "@dracula-show-network" true) show_weather=$(get_tmux_option "@dracula-show-weather" true) show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true) + show_location=$(get_tmux_option "@dracula-show-location" true) show_powerline=$(get_tmux_option "@dracula-show-powerline" false) show_flags=$(get_tmux_option "@dracula-show-flags" false) show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley) @@ -70,7 +71,7 @@ main() # start weather script in background if $show_weather; then - $current_dir/sleep_weather.sh $show_fahrenheit & + $current_dir/sleep_weather.sh $show_fahrenheit $show_location & fi # Set timezone unless hidden by configuration diff --git a/scripts/sleep_weather.sh b/scripts/sleep_weather.sh index d42adb0..0270409 100755 --- a/scripts/sleep_weather.sh +++ b/scripts/sleep_weather.sh @@ -3,6 +3,7 @@ #wrapper script for running weather on interval fahrenheit=$1 +location=$2 LOCKFILE=/tmp/.dracula-tmux-weather.lock @@ -27,7 +28,7 @@ main() while tmux has-session &> /dev/null do - $current_dir/weather.sh $fahrenheit > $current_dir/../data/weather.txt + $current_dir/weather.sh $fahrenheit $location > $current_dir/../data/weather.txt if tmux has-session &> /dev/null then sleep 1200 diff --git a/scripts/weather.sh b/scripts/weather.sh index b5bf371..dc7537a 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -1,19 +1,23 @@ #!/usr/bin/env bash - fahrenheit=$1 +location=$2 -load_request_params() +display_location() { - city=$(curl -s https://ipinfo.io/city 2> /dev/null) - region=$(curl -s https://ipinfo.io/region 2> /dev/null) + if $location; then + city=$(curl -s https://ipinfo.io/city 2> /dev/null) + region=$(curl -s https://ipinfo.io/region 2> /dev/null) + echo " $city, $region" + else + echo '' + fi } - fetch_weather_information() { display_weather=$1 - # it gets the weather condition textual name (%C), the temperature (%t), and the location (%l) + # it gets the weather condition textual name (%C), the temperature (%t), and the location (%l) curl -sL curl wttr.in\?format="+%C+%t$display_weather" } @@ -34,7 +38,7 @@ display_weather() echo "$unicode ${temperature/+/}" # remove the plus sign to the temperature } -forecast_unicode() +forecast_unicode() { weather_condition=$(echo $weather_condition | awk '{print tolower($0)}') @@ -53,10 +57,9 @@ forecast_unicode() main() { - load_request_params # process should be cancelled when session is killed if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then - echo "$(display_weather) $city, $region" + echo "$(display_weather)$(display_location)" else echo "Location Unavailable" fi From 87d43d0cc2be9ee40cbc6e2b5f0a05ce86b8e574 Mon Sep 17 00:00:00 2001 From: yzenati <9922120+yzenati@users.noreply.github.com> Date: Fri, 16 Oct 2020 12:32:43 +0200 Subject: [PATCH 2/6] Remove a extra curl in fetch_weather_information --- scripts/weather.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/weather.sh b/scripts/weather.sh index dc7537a..580b359 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -18,7 +18,7 @@ fetch_weather_information() { display_weather=$1 # it gets the weather condition textual name (%C), the temperature (%t), and the location (%l) - curl -sL curl wttr.in\?format="+%C+%t$display_weather" + curl -sL wttr.in\?format="+%C+%t$display_weather" } #get weather display From 9d9a5d2b144f7c38386c28b702236c854163a75e Mon Sep 17 00:00:00 2001 From: yzenati <9922120+yzenati@users.noreply.github.com> Date: Fri, 16 Oct 2020 12:41:02 +0200 Subject: [PATCH 3/6] Correct the comment of the curl command --- scripts/weather.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/weather.sh b/scripts/weather.sh index 580b359..c8e3ad9 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -17,7 +17,7 @@ display_location() fetch_weather_information() { display_weather=$1 - # it gets the weather condition textual name (%C), the temperature (%t), and the location (%l) + # it gets the weather condition textual name (%C), and the temperature (%t) curl -sL wttr.in\?format="+%C+%t$display_weather" } From 06f257d4829b8873b92bff42ae09b7623e8717be Mon Sep 17 00:00:00 2001 From: yzenati <9922120+yzenati@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:26:28 +0200 Subject: [PATCH 4/6] Change the way the separation of weater_condition and temperature are made, so it can take minus 0 temperature in celcius --- scripts/weather.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/weather.sh b/scripts/weather.sh index c8e3ad9..faa2783 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -31,8 +31,8 @@ display_weather() fi weather_information=$(fetch_weather_information $display_weather) - weather_condition=$(echo $weather_information | cut -d "+" -f 1 | cut -d "-" -f 1) # Sunny, Snow, etc - temperature=$(echo $weather_information | cut -d '+' -f 2) # +31°C, -3°F, etc + weather_condition=$(echo $weather_information | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc + temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc unicode=$(forecast_unicode $weather_condition) echo "$unicode ${temperature/+/}" # remove the plus sign to the temperature From 4020ae1d86b9781af913f683c2ba8783c13e5546 Mon Sep 17 00:00:00 2001 From: yzenati <9922120+yzenati@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:32:28 +0200 Subject: [PATCH 5/6] Remove the extra space at the beginning of the result of curl command --- scripts/weather.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/weather.sh b/scripts/weather.sh index faa2783..1c757b4 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -18,7 +18,7 @@ fetch_weather_information() { display_weather=$1 # it gets the weather condition textual name (%C), and the temperature (%t) - curl -sL wttr.in\?format="+%C+%t$display_weather" + curl -sL wttr.in\?format="%C+%t$display_weather" } #get weather display From e7a4bcf09f4ad56ad541aa2f7c1f5f7fe83acfe4 Mon Sep 17 00:00:00 2001 From: yzenati <9922120+yzenati@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:33:21 +0200 Subject: [PATCH 6/6] Only one space between the unicode and the temperature --- scripts/weather.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/weather.sh b/scripts/weather.sh index 1c757b4..7a5fd3c 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -35,7 +35,7 @@ display_weather() temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc unicode=$(forecast_unicode $weather_condition) - echo "$unicode ${temperature/+/}" # remove the plus sign to the temperature + echo "$unicode${temperature/+/}" # remove the plus sign to the temperature } forecast_unicode()