diff --git a/weather b/weather index d4a8b0a..1df4a64 100755 --- a/weather +++ b/weather @@ -16,6 +16,7 @@ options: -s, --search returns the weather for QUERY -u, --units sets the temperature units -i, --icon_test tests the icons used + -r, --radar requests the radar for a given location -h, --help displays this message ZIPCODE sets the location to the given zipcode @@ -267,6 +268,28 @@ load_info() { } +display_radar() { + # two step process, gets weather station from NWS, then mpv to play radar + if [[ -z "$LAT" || -z "$LON" ]] ; then + echo "Location not found!" + exit 1 + fi + # grabbing nws station + NWS=$(curl -fsSL "https://api.weather.gov/points/$LAT,$LON") + STATION=$(echo "$NWS" | gojq '.properties.radarStation' | tr -d '"') + + # validation + if [[ -z "$STATION" ]] ; then + echo "NWS Station error!" + exit 1 + fi + # mpv to play weather in fullscreen + echo "Fetching weather for NWS Station $STATION..." + mpv --fs --loop-file "https://radar.weather.gov/ridge/standard/${STATION}_loop.gif" >/dev/null 2>&1 + + exit 0 +} + get_icon() { # sets NF symbols tod=$(echo "$1" | sed --expression='s/[0-9]//g') @@ -337,6 +360,7 @@ icon_test() { printf 'Degrees (F) \ufa04\n' printf 'Degrees (C) \ufa03\n' printf '%% Humidity \ue373\n' + exit 0 } # shifting longform @@ -352,6 +376,7 @@ for arg in "$@"; do '--pretty') set -- "$@" "-p" ;; '--pretty') set -- "$@" "-p" ;; '--icon_test') set -- "$@" "-i" ;; + '--radar') set -- "$@" "-r" ;; '--help') set -- "$@" "-h" ;; *) set -- "$@" "$arg" ;; esac @@ -360,7 +385,7 @@ done # loading the info load_info -while getopts "chpldiz:s:u:a:" opt; do +while getopts "chpldriz:s:u:a:" opt; do case "$opt" in 'a' ) API_KEY="$OPTARG" @@ -387,7 +412,9 @@ while getopts "chpldiz:s:u:a:" opt; do ;; 'i' ) icon_test - exit 0 + ;; + 'r' ) + display_radar ;; 'h' ) usage 0