From 70efff35421f84f46c7c02bbe9bd4cb91475afdd Mon Sep 17 00:00:00 2001 From: stkhan Date: Thu, 23 May 2024 21:50:13 -0500 Subject: only download location json once --- README | 7 ++++++- nws | 24 ++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README b/README index 928f69a..ac1bd8e 100644 --- a/README +++ b/README @@ -1,3 +1,8 @@ nws - a command-line weather service -nws retrieves data from the National Weather Service, and displays it in your terminal. Coordinate location is provided by ipinfo.io. +nws retrieves data from the National Weather Service, and displays it in your terminal. + +## Location + +nws gets location by getting info from ipinfo.io, which uses your IP address. It may inaccurate, so you may have +to manually edit ~/.config/nws/location.json. diff --git a/nws b/nws index dab2397..45dac5f 100755 --- a/nws +++ b/nws @@ -2,7 +2,7 @@ # nws - a National Weather Service terminal client # git.slickd.xyz/nws -source ~/.config/nws/nws.conf +source $HOME/.config/nws/nws.conf version=v0.0.4 colors() { @@ -22,12 +22,12 @@ save_json() { 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) + curl -s ipinfo.io>> "${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 + 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 + curl -s https://api.weather.gov/alerts/active/zone/"${countyId}" >> "${OUTPUT}"/alerts.json echo -e \n\nFinished } @@ -47,10 +47,14 @@ retrieve_counties() { get_location() { - file=$(curl ipinfo.io/json >> /tmp/nws/loc) - cords=$(jq -r '.loc' /tmp/nws/loc) - city=$(jq -r '.city' /tmp/nws/loc) - state=$(jq -r '.region' /tmp/nws/loc) + if [ ! -f ~/.config/nws/location.json ]; then + echo Downloading file + curl ipinfo.io >> ~/.config/nws/location.json + else + cords=$(jq -r '.loc' ~/.config/nws/location.json) + city=$(jq -r '.city' ~/.config/nws/location.json) + state=$(jq -r '.region' ~/.config/nws/location.json) + fi } show_radar() { @@ -168,7 +172,7 @@ help() { echo "Other operations:" echo echo " --retrieve-counties: shows county ids" - echo " --save-json: saves JSON files used to a directory" + 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 -- cgit v1.2.3