summaryrefslogtreecommitdiff
path: root/nws
diff options
context:
space:
mode:
authorstkhan <personal@slickd.xyz>2024-05-23 21:50:13 -0500
committerstkhan <personal@slickd.xyz>2024-05-23 21:50:13 -0500
commit70efff35421f84f46c7c02bbe9bd4cb91475afdd (patch)
tree4334b1b96019ec12c38eff16076021a1359be0c9 /nws
parent21a89269118d1ce918fb1f58856367cdbaa1a404 (diff)
only download location json once
Diffstat (limited to 'nws')
-rwxr-xr-xnws24
1 files changed, 14 insertions, 10 deletions
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