tmux-kanagawa/scripts/weather.sh

36 lines
646 B
Bash
Raw Normal View History

2020-03-15 00:57:01 +01:00
#!/usr/bin/env bash
2020-04-29 20:33:51 +02:00
fahrenheit=$1
2020-03-15 03:21:31 +01:00
weather_information()
{
display_weather=$1
# it gets the weather condition (%c), the temperature (%t), and the location (%l)
curl -sL curl wttr.in\?format="+%c+%t+%l$display_weather"
2020-03-15 03:21:31 +01:00
}
#get weather display
2020-03-15 03:21:31 +01:00
display_weather()
{
if $fahrenheit; then
display_weather='&u' # for USA system
2020-03-15 03:21:31 +01:00
else
display_weather='&m' # for metric system
2020-03-15 03:21:31 +01:00
fi
echo $(weather_information $display_weather)
2020-03-15 03:21:31 +01:00
}
2020-03-15 00:57:01 +01:00
main()
{
# process should be cancelled when session is killed
2020-03-15 03:21:31 +01:00
if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then
echo "$(display_weather)"
2020-03-15 03:21:31 +01:00
else
echo "Location Unavailable"
fi
2020-03-15 00:57:01 +01:00
}
#run main driver program
main