spcget/spcget

120 lines
4.6 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# spcget: gets the NOAA national weather forecast map gifs and displays them
# with the default system image viewer.
# help: help text
help() {
cat << EOF
usage: spcget <product>
All forecasts come from NOAA's Storm Prediction Center; advisories, watches and
warnings are issued by the National Weather Service.
fire, fire2, fire3 - Fire Weather Outlooks:
Fire weather outlooks on day 1, 2 and 3-8.
msd <map number> - Mesoscale Discussions:
Areas where a thunderstorm or winter weather are active. Areas in red
indicate thunderstorms, areas in blue indicate winter weather. They
highlight areas where there's a more detailed description of the event
in progress with more detailed information on those maps. Add the map
number to see a detailed map for a given area.
msdlist <Ymd> or <today> - List of currently issued MSDs.
Use spcget msdlist today to see all issued MSDs from today, including expired ones.
Use spcget msdlist <date> to see all issued MSDs for any day.
Ex: spcget msdlist 20200101 to see the MSDs issued on 2020-01-01.
tstm, tstm2, tstm3, tstm4 - Thunderstorm Outlooks:
Chance for thunderstorms on a 6 point scale on days 1, 2, 3 and 4-8.
tstmnow - Current Thunderstorm Outlook:
Chance for thunderstorms within the next 4 to 8 hours.
watch - Current NOAA Thunderstorm and Tornado Watches:
Areas in blue are severe thunderstorm watches, areas in red are tornado
watches.
warnings - Current NWS Advisories, Watches and Warnings:
Legend for this map can be viewed at https://www.spc.noaa.gov/products/wwa/
EOF
}
# get the correct URL for the product specified
case "$1" in
# fire weather outlooks, day 1, 2, 3-8
fire) GETURL="https://www.spc.noaa.gov/products/fire_wx/day1otlk_fire.gif";;
fire2) GETURL="https://www.spc.noaa.gov/products/fire_wx/day2otlk_fire.gif";;
fire3) GETURL="https://www.spc.noaa.gov/products/exper/fire_wx/imgs/day38otlk_fire.gif";;
# mesoscale discussions
msd)
GETURL="https://www.spc.noaa.gov/products/md/validmd.png"
if [ ! -z "$2" ]; then
GETURL="https://www.spc.noaa.gov/products/md/mcd$2.gif"
else
echo "Legend: Blue for Winter Weather, Red for Thunderstorms."
echo "For more detailed info, look up the specific map with spcget msd <map number>"
fi
;;
# get list of currently issued mesoscale discussions, or by date
msdlist)
if [ ! -z "$2" ]; then
case "$2" in
today)
echo "Today's Issued Mesoscale Discussion Maps"
DATE=`date "+%Y%m%d"`
curl -s "https://www.spc.noaa.gov/cgi-bin-spc/getmd.pl?target=$DATE"\
| grep -oh "\w*md\w*.html" | sed 's/md//g ;; s/.html//g' | sort | uniq
exit 0
;;
*)
echo "Issued Mesoscale Discussion Maps for $2"
curl -s "https://www.spc.noaa.gov/cgi-bin-spc/getmd.pl?target=$2"\
| grep -oh "\w*md\w*.html" | sed 's/md//g ;; s/.html//g' | sort | uniq
exit 0
;;
esac
else
echo "Current Mesoscale Discussion Maps"
curl -s "https://www.spc.noaa.gov/products/md/"\
| grep -oh "\w*md\w*.html" | sed 's/md//g ;; s/.html//g' | sort | uniq
exit 0
fi
;;
# thunderstorm outlooks, day 1, 2, 3, 4-8
tstm) GETURL="https://www.spc.noaa.gov/products/outlook/day1otlk.gif";;
tstm2) GETURL="https://www.spc.noaa.gov/products/outlook/day2otlk.gif";;
tstm3) GETURL="https://www.spc.noaa.gov/products/outlook/day3otlk.gif";;
tstm4) GETURL="https://www.spc.noaa.gov/products/exper/day4-8/day48prob.gif";;
# thunderstorm outlook, 4-8 hours
tstmnow) GETURL="https://www.spc.noaa.gov/products/exper/enhtstm/imgs/enh_0000.gif";;
# current thunderstorm and tornado watches
watch)
GETURL="https://www.spc.noaa.gov/products/watch/validww.png"
echo "Legend: Blue for Severe Thunderstorms, Red for Tornadoes"
;;
# all weather advisories across the lower 48
warnings)
GETURL="https://forecast.weather.gov/wwamap/png/US.png"
echo "Legend at https://www.spc.noaa.gov/products/wwa/"
;;
# help
help)
help
exit 0
;;
*)
echo "Invalid product specified"
echo
help
exit 1
;;
esac
echo "Source URL: $GETURL"
curl -s "$GETURL" | { tf=$(mktemp); cat >"$tf"; echo "$tf";} | xargs xdg-open \
>/dev/null 2>&1
exit 0