Merge pull request #78 from yzenati/location_option

Add an option to disable the location information in the weather
This commit is contained in:
Ethan Edwards 2020-10-17 15:10:53 -04:00 committed by GitHub
commit 84af549a13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 14 deletions

View file

@ -23,6 +23,7 @@ main()
show_network=$(get_tmux_option "@dracula-show-network" true) show_network=$(get_tmux_option "@dracula-show-network" true)
show_weather=$(get_tmux_option "@dracula-show-weather" true) show_weather=$(get_tmux_option "@dracula-show-weather" true)
show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" 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_powerline=$(get_tmux_option "@dracula-show-powerline" false)
show_flags=$(get_tmux_option "@dracula-show-flags" false) show_flags=$(get_tmux_option "@dracula-show-flags" false)
show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley) show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley)
@ -72,7 +73,7 @@ main()
# start weather script in background # start weather script in background
if $show_weather; then if $show_weather; then
$current_dir/sleep_weather.sh $show_fahrenheit & $current_dir/sleep_weather.sh $show_fahrenheit $show_location &
fi fi
# Set timezone unless hidden by configuration # Set timezone unless hidden by configuration

View file

@ -5,6 +5,7 @@ export LC_ALL=en_US.UTF-8
#wrapper script for running weather on interval #wrapper script for running weather on interval
fahrenheit=$1 fahrenheit=$1
location=$2
LOCKFILE=/tmp/.dracula-tmux-weather.lock LOCKFILE=/tmp/.dracula-tmux-weather.lock
@ -29,7 +30,7 @@ main()
while tmux has-session &> /dev/null while tmux has-session &> /dev/null
do 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 if tmux has-session &> /dev/null
then then
sleep 1200 sleep 1200

View file

@ -3,19 +3,24 @@
export LC_ALL=en_US.UTF-8 export LC_ALL=en_US.UTF-8
fahrenheit=$1 fahrenheit=$1
location=$2
load_request_params() display_location()
{ {
city=$(curl -s https://ipinfo.io/city 2> /dev/null) if $location; then
region=$(curl -s https://ipinfo.io/region 2> /dev/null) 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() fetch_weather_information()
{ {
display_weather=$1 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 curl wttr.in\?format="+%C+%t$display_weather" curl -sL wttr.in\?format="%C+%t$display_weather"
} }
#get weather display #get weather display
@ -28,11 +33,11 @@ display_weather()
fi fi
weather_information=$(fetch_weather_information $display_weather) weather_information=$(fetch_weather_information $display_weather)
weather_condition=$(echo $weather_information | cut -d "+" -f 1 | cut -d "-" -f 1) # Sunny, Snow, etc weather_condition=$(echo $weather_information | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc
temperature=$(echo $weather_information | cut -d '+' -f 2) # +31°C, -3°F, etc temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
unicode=$(forecast_unicode $weather_condition) 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() forecast_unicode()
@ -54,10 +59,9 @@ forecast_unicode()
main() main()
{ {
load_request_params
# process should be cancelled when session is killed # process should be cancelled when session is killed
if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then
echo "$(display_weather) $city, $region" echo "$(display_weather)$(display_location)"
else else
echo "Location Unavailable" echo "Location Unavailable"
fi fi