diff options
| author | stkhan <personal@slickd.xyz> | 2024-05-23 21:50:13 -0500 |
|---|---|---|
| committer | stkhan <personal@slickd.xyz> | 2024-05-23 21:50:13 -0500 |
| commit | 70efff35421f84f46c7c02bbe9bd4cb91475afdd (patch) | |
| tree | 4334b1b96019ec12c38eff16076021a1359be0c9 | |
| parent | 21a89269118d1ce918fb1f58856367cdbaa1a404 (diff) | |
only download location json once
| -rw-r--r-- | README | 7 | ||||
| -rwxr-xr-x | nws | 24 |
2 files changed, 20 insertions, 11 deletions
@@ -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. @@ -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 |