diff options
| author | stkhan <personal@slickd.xyz> | 2024-05-15 21:51:11 -0500 |
|---|---|---|
| committer | stkhan <personal@slickd.xyz> | 2024-05-15 21:51:11 -0500 |
| commit | 21a89269118d1ce918fb1f58856367cdbaa1a404 (patch) | |
| tree | 66c3efb9680b271e287a005f647c7281381ee73e | |
| parent | f72713797fde4893014d3b1c94fc762611d1cda0 (diff) | |
update to 0.0.4
| -rwxr-xr-x | nws | 48 |
1 files changed, 38 insertions, 10 deletions
@@ -3,7 +3,7 @@ # git.slickd.xyz/nws source ~/.config/nws/nws.conf -version=v0.0.3 +version=v0.0.4 colors() { NOCOLOR='\033[0m' @@ -12,7 +12,23 @@ colors() { } cleanup() { - rm -rf ~/.cache/.county_ids ~/.cache/.weather_forecast ~/.cache/.weather_alerts /tmp/nws/ + rm -rf ~/.cache/.county_ids ~/.cache/.weather_forecast ~/.cache/.weather_alerts /tmp/nws/ ~/.config/nws/cache/ +} + +save_json() { + if [ -z "${OUTPUT}" ]; + then + echo You must specify an output directory. + exit + fi + echo -ne "Downloading files... (1 of 3)\r" + curl -s ipinfo.io/json >> ${OUTPUT}/location.json + cords=$(jq -r '.loc' ${OUTPUT}/location.json) + echo -ne "Downloading files... (2 of 3)\r" + curl -s https://api.weather.gov/points/$cords >> ${OUTPUT}/weather.json + echo -ne "Downloading files... (3 of 3)\r" + curl -s https://api.weather.gov/alerts/active/zone/${countyId} >> ${OUTPUT}/alerts.json + echo -e \n\nFinished } retrieve_counties() { @@ -93,26 +109,26 @@ show_spc() { } get_graphicast() { - mkdir -p /tmp/nws/ + mkdir -p ~/.config/nws/cache/ count=1 prog=12.5 bar="#" while [ $count -le 8 ] do - wget -q -P /tmp/nws https://www.weather.gov/images/oun/graphicast/image${count}.png + wget -q -P ~/.config/nws/cache https://www.weather.gov/images/oun/graphicast/image${count}.png echo -ne "${bar} (${prog}%)\r" ((count++)) prog=$(echo "$prog + 12.5" | bc) bar="${bar}#" done echo "Getting Mesonet radar..." - wget -q -P /tmp/nws https://data.mesonet.org/data/nids/maps/realtime/${state_full}.MosaicBREF.png - $IV /tmp/nws/* + wget -q -P ~/.config/nws/cache/ https://data.mesonet.org/data/nids/maps/realtime/${state_full}.MosaicBREF.png + $IV ~/.config/nws/cache/* } get_forecast() { colors - mkdir -p /tmp/nws/ + mkdir -p ~/.config/nws/cache/ get_location curl $(curl https://api.weather.gov/points/$cords | jq -r .properties.forecast) >> ~/.cache/.weather_forecast count=0 @@ -141,21 +157,31 @@ get_forecast() { help() { echo "nws $version" echo + echo "Basic operations:" + echo + echo " -f: shows local forecast" + echo " -a: shows weather alerts" echo " --radar (1,2,3): shows local radar" echo " --spc: shows storm predictions" + echo + echo + echo "Other operations:" + echo echo " --retrieve-counties: shows county ids" + echo " --save-json: saves JSON files used to a directory" echo " --ca: shows number of alerts" echo " --gc: shows graphic forecast, uses image viewer set in config" - echo " -a: shows alerts" - echo " -f: shows local forecast" echo } -cleanup + radar_choice=$2 +OUTPUT=$2 + case $1 in '--radar') show_radar;; '--spc') show_spc;; '--retrieve-counties') retrieve_counties;; + '--save-json') save_json;; '--ca') count_alerts;; '--gc') get_graphicast;; '-a') show_alerts | sed 's/null//g ; s/"//g' |less -R;; @@ -164,3 +190,5 @@ case $1 in '--help') help;; "") help;; esac + +cleanup |