In Hope of Nice Weekend Weather
Maybe I’m just desperate for a nice weather weekend, or I wanted to practice my skills for work, but I created this quick little bash script that runs on the 29 and 59 minutes of each hour, so I get the latest NOAA forecast for the weekend, hot off the presses displayed on my screen for the weekend.
#!/bin/bash
wget "https://forecast.weather.gov/MapClick.php?lat=42.4686&lon=-73.9294&unit=0&lg=english&FcstType=dwml" -O /var/tmp/forecast.xml
WEEKENDS=( Friday Saturday Sunday )
for WEEKEND in "${WEEKENDS[@]}"
do
DAY=$(xmllint /var/tmp/forecast.xml --xpath '/dwml/data/time-layout[2]/start-valid-time' | awk /$WEEKEND\"/'{print NR}')
DAY12=$(xmllint /var/tmp/forecast.xml --xpath '/dwml/data/time-layout[1]/start-valid-time' | awk /$WEEKEND\"/'{print NR}')
DAY12NIGHT=$((DAY12+1))
HIGH=$(xmllint /var/tmp/forecast.xml --xpath "/dwml/data/parameters/temperature[@type=\"maximum\"]/value[$DAY]/text()" 2>/dev/null)
LOW=$(xmllint /var/tmp/forecast.xml --xpath "/dwml/data/parameters/temperature[@type=\"minimum\"]/value[$DAY]/text()" 2> /dev/null)
DAYSUMMARY=$(xmllint /var/tmp/forecast.xml --xpath "string(/dwml/data/parameters/weather/weather-conditions[$DAY12]/@weather-summary)" 2> /dev/null)
NIGHTSUMMARY=$(xmllint /var/tmp/forecast.xml --xpath "string(/dwml/data/parameters/weather/weather-conditions[$DAY12NIGHT]/@weather-summary)" 2> /dev/null)
[[ $WEEKEND == Saturday ]] && xmllint /var/tmp/forecast.xml --xpath "/dwml/data/parameters/conditions-icon/icon-link[$DAY12]/text()" 2> /dev/null | wget -i - -O /var/tmp/wxicon.png
[[ -z $HIGH ]] || OUTPUT+="\n $WEEKEND: "
[[ -z $HIGH ]] || OUTPUT+="$DAYSUMMARY $HIGH "
[[ -z $LOW ]] || OUTPUT+="/ $NIGHTSUMMARY $LOW"
done
notify-send "Weekend Weather Update" "$OUTPUT" -t 15000 -i /var/tmp/wxicon.png