2021-05-11 10:51:27 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
[ -z "${XDG_CONFIG_DIR}" ] && XDG_CONFIG_DIR="${HOME}/.config"
|
|
|
|
[ -z "${NWS_CONFIG}" ] && NWS_CONFIG="${XDG_CONFIG_DIR}/nws"
|
|
|
|
[ -n "${NWS_ZONE}" ] || \
|
2022-11-27 11:04:53 -06:00
|
|
|
[ -e "${NWS_CONFIG}" ] && NWS_ZONE=$(cat "${NWS_CONFIG}") ||
|
|
|
|
NWS_ZONE="KGYX"
|
2021-05-11 10:51:27 -05:00
|
|
|
[ -z "${NWS_GIF}" ] && NWS_GIF="mpv --loop"
|
|
|
|
[ -z "${NWS_TORIFY}" ] && NWS_TORIFY=""
|
|
|
|
|
|
|
|
|
|
|
|
info () {
|
|
|
|
printf %s "\
|
|
|
|
nws - wrapper for the National Weather Service's website
|
|
|
|
|
|
|
|
=> [n]ational - View national weather mosaic
|
|
|
|
=> [l]ocal - View local weather mosaic
|
|
|
|
=> [r]ivers - View local river conditions
|
2021-05-11 13:10:50 -05:00
|
|
|
=> [w]eather - View local weather observations
|
|
|
|
=> [m]osaic [id] - View a given area's weather mosaic
|
|
|
|
=> [s]et [id] - Set local zone
|
|
|
|
=> [t]ext [id] - View text messages by catagory
|
2021-05-11 10:51:27 -05:00
|
|
|
|
|
|
|
Default zone: export NWS_ZONE=<zone>
|
|
|
|
GIF player: export NWS_GIF=<command>
|
|
|
|
Configuration: export NWS_CONFIG=<file>
|
|
|
|
Torify wrapper: export NWS_TORIFY=<command>
|
|
|
|
"
|
|
|
|
}
|
|
|
|
err () {
|
2022-11-27 11:04:53 -06:00
|
|
|
printf "err: %s\n" "${1}"
|
2022-06-13 16:39:17 -05:00
|
|
|
[ -z "${2}" ] && exit 1
|
2022-11-27 11:04:53 -06:00
|
|
|
exit "${2}"
|
2021-05-11 10:51:27 -05:00
|
|
|
}
|
2021-05-11 13:10:50 -05:00
|
|
|
kstrip () {
|
2022-06-13 16:39:17 -05:00
|
|
|
printf %s "$1" | sed 's/^K\(.*\)/\1/'
|
2021-05-11 13:10:50 -05:00
|
|
|
}
|
2021-05-11 10:51:27 -05:00
|
|
|
national () {
|
2022-06-13 16:39:17 -05:00
|
|
|
mosaic CONUS-LARGE
|
2021-05-11 10:51:27 -05:00
|
|
|
}
|
|
|
|
# name interestingly to avoid keyword collision
|
|
|
|
localradar () {
|
2022-06-13 16:39:17 -05:00
|
|
|
mosaic ${NWS_ZONE}
|
2021-05-11 13:10:50 -05:00
|
|
|
}
|
|
|
|
mosaic () {
|
2022-06-13 16:39:17 -05:00
|
|
|
${NWS_GIF} "https://radar.weather.gov/ridge/lite/${1}_loop.gif"
|
2021-05-11 10:51:27 -05:00
|
|
|
}
|
|
|
|
setzone () {
|
2022-11-27 11:04:53 -06:00
|
|
|
printf "%s" "${1}" > "${NWS_CONFIG}"
|
2021-05-11 10:51:27 -05:00
|
|
|
}
|
|
|
|
river () {
|
2022-06-13 16:39:17 -05:00
|
|
|
textmessage "RVA"
|
2021-05-11 13:10:50 -05:00
|
|
|
}
|
|
|
|
weather () {
|
2022-06-13 16:39:17 -05:00
|
|
|
textmessage "ZFP"
|
2021-05-11 13:10:50 -05:00
|
|
|
}
|
|
|
|
textmessage () {
|
2022-06-13 16:39:17 -05:00
|
|
|
curl --silent --fail "https://forecast.weather.gov/product.php?site=NWS&issuedby=$(kstrip ${NWS_ZONE})&product=${1}&format=TXT&version=1" | \
|
|
|
|
sed -n '/<!-- \/\/ CONTENT STARTS HERE -->/,/<\/pre>/p' | \
|
|
|
|
grep -v "a href" | \
|
|
|
|
grep -v '<!-- // CONTENT STARTS HERE -->' | \
|
|
|
|
grep -v '<\/pre>' || \
|
|
|
|
printf "${1} data not found for zone %s" ${NWS_ZONE}
|
2021-05-11 10:51:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
2022-06-13 16:39:17 -05:00
|
|
|
"n"*)
|
|
|
|
national
|
|
|
|
;;
|
|
|
|
"l"*)
|
|
|
|
localradar
|
|
|
|
;;
|
|
|
|
"r"*)
|
|
|
|
river
|
|
|
|
;;
|
|
|
|
"w"*)
|
|
|
|
weather
|
|
|
|
;;
|
|
|
|
"m"*)
|
2022-11-27 11:04:53 -06:00
|
|
|
if [ "$#" -eq 2 ]; then
|
|
|
|
mosaid "$2"
|
|
|
|
else
|
2022-06-13 16:39:17 -05:00
|
|
|
err "two args required"
|
2022-11-27 11:04:53 -06:00
|
|
|
fi
|
2022-06-13 16:39:17 -05:00
|
|
|
;;
|
|
|
|
"s"*)
|
2022-11-27 11:04:53 -06:00
|
|
|
if [ "$#" -eq 2 ]; then
|
|
|
|
setzone "$2"
|
|
|
|
else
|
2022-06-13 16:39:17 -05:00
|
|
|
err "two args required"
|
2022-11-27 11:04:53 -06:00
|
|
|
fi
|
2022-06-13 16:39:17 -05:00
|
|
|
;;
|
|
|
|
"t"*)
|
2022-11-27 11:04:53 -06:00
|
|
|
if [ "$#" -eq 2 ]; then
|
|
|
|
textmessage "$2"
|
|
|
|
else
|
2022-06-13 16:39:17 -05:00
|
|
|
err "two args required"
|
2022-11-27 11:04:53 -06:00
|
|
|
fi
|
2022-06-13 16:39:17 -05:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
info
|
|
|
|
;;
|
2021-05-11 10:51:27 -05:00
|
|
|
esac
|
|
|
|
exit 0
|