Add an option to disable the location information in the weather
This commit is contained in:
parent
8cf4901842
commit
f5c0789d07
3 changed files with 16 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue