added weather

This commit is contained in:
Dane Williams 2020-03-14 19:21:31 -07:00
parent 7e6749c848
commit eac3e9167a
3 changed files with 55 additions and 2 deletions

Binary file not shown.

View file

@ -44,7 +44,7 @@ main()
tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #(~/.tmux/plugins/tmux-dracula/battery.sh) " tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #(~/.tmux/plugins/tmux-dracula/battery.sh) "
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] tructus " tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] tructus "
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] flazen " tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #(~/.tmux/plugins/tmux-dracula/weather.sh) "
tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p #(date +%Z) " tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p #(date +%Z) "
# window tabs # window tabs

View file

@ -5,11 +5,64 @@
#script is then called in the dracula.tmux program #script is then called in the dracula.tmux program
city=$(curl -s https://ipinfo.io/city 2> /dev/null) city=$(curl -s https://ipinfo.io/city 2> /dev/null)
region=$(curl -s https://ipinfo.io/region 2> /dev/null)
zip=$(curl -s https://ipinfo.io/postal 2> /dev/null | tail -1)
country=$(curl -s https://ipinfo.io/country 2> /dev/null)
region_code_url=http://www.ip2country.net/ip2country/region_code.html
weather_url=https://forecast.weather.gov/zipcity.php
zip=46556
#substitute region code for regions in north america
get_region_code()
{
curl -s $region_code_url | grep $region &> /dev/null && region=$(curl -s $region_code_url | grep $region | cut -d ',' -f 2)
echo $region
}
weather_information()
{
curl -sL $weather_url?inputstring=$zip | grep myforecast-current | grep -Eo '>.*<' | sed -E 's/>(.*)</\1/'
}
get_temp()
{
weather_information | grep 'deg;F' | cut -d '&' -f 1
}
forecast_unicode()
{
forecast=$(weather_information | head -n 1)
if [[ $forecast =~ 'Snow' ]]; then
echo '❄'
elif [[ (($forecast =~ 'Rain') || ($forecast =~ 'Shower')) ]]; then
echo '☂'
elif [[ (($forecast =~ 'Overcast') || ($forecast =~ 'Cloud')) ]]; then
echo '☁'
else
echo '☀'
fi
}
#get weather display if in US
display_weather()
{
if [ $country = 'US' ]; then
echo " $(forecast_unicode) $(get_temp)°F"
else
echo ''
fi
}
main() main()
{ {
echo $IP if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then
echo "$(display_weather) $city, $(get_region_code)"
else
echo "Location Unavailable"
fi
} }
#run main driver program #run main driver program