update nws
This commit is contained in:
parent
751bf87e06
commit
e1b91a53e1
39
scripts/nws
39
scripts/nws
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -x
|
|
||||||
|
|
||||||
[ -z "${XDG_CONFIG_DIR}" ] && XDG_CONFIG_DIR="${HOME}/.config"
|
[ -z "${XDG_CONFIG_DIR}" ] && XDG_CONFIG_DIR="${HOME}/.config"
|
||||||
[ -z "${NWS_CONFIG}" ] && NWS_CONFIG="${XDG_CONFIG_DIR}/nws"
|
[ -z "${NWS_CONFIG}" ] && NWS_CONFIG="${XDG_CONFIG_DIR}/nws"
|
||||||
[ -n "${NWS_ZONE}" ] || \
|
[ -n "${NWS_ZONE}" ] || \
|
||||||
|
@ -18,11 +16,10 @@ nws - wrapper for the National Weather Service's website
|
||||||
=> [n]ational - View national weather mosaic
|
=> [n]ational - View national weather mosaic
|
||||||
=> [l]ocal - View local weather mosaic
|
=> [l]ocal - View local weather mosaic
|
||||||
=> [r]ivers - View local river conditions
|
=> [r]ivers - View local river conditions
|
||||||
=> [w]eather - View local weather observations [!]
|
=> [w]eather - View local weather observations
|
||||||
=> [m]osaic [id] - View a given area's weather mosaic [!]
|
=> [m]osaic [id] - View a given area's weather mosaic
|
||||||
=> [z]ones - List internal zone names [!]
|
=> [s]et [id] - Set local zone
|
||||||
=> [s]et [id] - Set local zone [!]
|
=> [t]ext [id] - View text messages by catagory
|
||||||
=> [o]bservations - View observations in specific catagories [!]
|
|
||||||
|
|
||||||
Default zone: export NWS_ZONE=<zone>
|
Default zone: export NWS_ZONE=<zone>
|
||||||
GIF player: export NWS_GIF=<command>
|
GIF player: export NWS_GIF=<command>
|
||||||
|
@ -35,23 +32,35 @@ err () {
|
||||||
[ -z "${2}" ] && exit 1
|
[ -z "${2}" ] && exit 1
|
||||||
exit ${2}
|
exit ${2}
|
||||||
}
|
}
|
||||||
|
kstrip () {
|
||||||
|
printf %s "$1" | sed 's/^K\(.*\)/\1/'
|
||||||
|
}
|
||||||
national () {
|
national () {
|
||||||
${NWS_GIF} 'https://radar.weather.gov/ridge/lite/CONUS-LARGE_loop.gif'
|
mosaic CONUS-LARGE
|
||||||
}
|
}
|
||||||
# name interestingly to avoid keyword collision
|
# name interestingly to avoid keyword collision
|
||||||
localradar () {
|
localradar () {
|
||||||
${NWS_GIF} "https://radar.weather.gov/ridge/lite/${NWS_ZONE}_loop.gif"
|
mosaic ${NWS_ZONE}
|
||||||
|
}
|
||||||
|
mosaic () {
|
||||||
|
${NWS_GIF} "https://radar.weather.gov/ridge/lite/${1}_loop.gif"
|
||||||
}
|
}
|
||||||
setzone () {
|
setzone () {
|
||||||
printf "%s" "${1}" > ${NWS_CONFIG}
|
printf "%s" "${1}" > ${NWS_CONFIG}
|
||||||
}
|
}
|
||||||
river () {
|
river () {
|
||||||
curl "https://forecast.weather.gov/product.php?site=NWS&issuedby=${NWS_ZONE}&product=RVA&format=TXT&version=1" | \
|
textmessage "RVA"
|
||||||
|
}
|
||||||
|
weather () {
|
||||||
|
textmessage "ZFP"
|
||||||
|
}
|
||||||
|
textmessage () {
|
||||||
|
curl --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' | \
|
sed -n '/<!-- \/\/ CONTENT STARTS HERE -->/,/<\/pre>/p' | \
|
||||||
grep -v "a href" | \
|
grep -v "a href" | \
|
||||||
grep -v '<!-- // CONTENT STARTS HERE -->' | \
|
grep -v '<!-- // CONTENT STARTS HERE -->' | \
|
||||||
grep -v '<\/pre>' || \
|
grep -v '<\/pre>' || \
|
||||||
printf "river data not found for zone %s" ${NWS_ZONE}
|
printf "${1} data not found for zone %s" ${NWS_ZONE}
|
||||||
}
|
}
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
|
@ -68,8 +77,12 @@ case $1 in
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
"w"*)
|
"w"*)
|
||||||
|
weather
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
"m"*)
|
"m"*)
|
||||||
|
[ $# -eq 2 ] && mosaid $2 || \
|
||||||
|
err "two args required"
|
||||||
;;
|
;;
|
||||||
"z"*)
|
"z"*)
|
||||||
;;
|
;;
|
||||||
|
@ -78,7 +91,9 @@ case $1 in
|
||||||
err "two args required"
|
err "two args required"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
"o"*)
|
"t"*)
|
||||||
|
[ $# -eq 2 ] && textmessage $2 || \
|
||||||
|
err "two args required"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
info
|
info
|
||||||
|
|
Loading…
Reference in New Issue