fixed weather script to only update every 30 seconds and persist location data to last seen
parent
1840aea989
commit
2e087b18c0
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 66fe519826ba9b6870422179c368ea5d3a97e890
|
@ -0,0 +1,4 @@
|
|||||||
|
STATE=MA
|
||||||
|
CITY=Cambridge
|
||||||
|
LAT=42.3737
|
||||||
|
LON=-71.1284
|
@ -1,66 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
var USStates = map[string]string{
|
|
||||||
"New Jersey": "NJ",
|
|
||||||
"Ohio": "OH",
|
|
||||||
"Pennsylvania": "PA",
|
|
||||||
"Vermont": "VT",
|
|
||||||
"Georgia": "GA",
|
|
||||||
"Hawaii": "HI",
|
|
||||||
"New Hampshire": "NH",
|
|
||||||
"Utah": "UT",
|
|
||||||
"Oklahoma": "OK",
|
|
||||||
"South Carolina": "SC",
|
|
||||||
"South Dakota": "SD",
|
|
||||||
"Illinois": "IL",
|
|
||||||
"New York": "NY",
|
|
||||||
"Armed Forces Europe": "AE",
|
|
||||||
"Armed Forces Pacific": "AP",
|
|
||||||
"Connecticut": "CT",
|
|
||||||
"Kansas": "KS",
|
|
||||||
"Wisconsin": "WI",
|
|
||||||
"Tennessee": "TN",
|
|
||||||
"Palau": "PW",
|
|
||||||
"California": "CA",
|
|
||||||
"Louisiana": "LA",
|
|
||||||
"Michigan": "MI",
|
|
||||||
"Rhode Island": "RI",
|
|
||||||
"Armed Forces Americas": "AA",
|
|
||||||
"Alabama": "AL",
|
|
||||||
"Arizona": "AZ",
|
|
||||||
"North Dakota": "ND",
|
|
||||||
"Colorado": "CO",
|
|
||||||
"Guam": "GU",
|
|
||||||
"Virgin Islands": "VI",
|
|
||||||
"Alaska": "AK",
|
|
||||||
"Indiana": "IN",
|
|
||||||
"Iowa": "IA",
|
|
||||||
"District of Columbia": "DC",
|
|
||||||
"Marshall Islands": "MH",
|
|
||||||
"Puerto Rico": "PR",
|
|
||||||
"Montana": "MT",
|
|
||||||
"New Mexico": "NM",
|
|
||||||
"North Carolina": "NC",
|
|
||||||
"Arkansas": "AR",
|
|
||||||
"Maryland": "MD",
|
|
||||||
"Massachusetts": "MA",
|
|
||||||
"Delaware": "DE",
|
|
||||||
"Maine": "ME",
|
|
||||||
"Northern Mariana Islands": "MP",
|
|
||||||
"West Virginia": "WV",
|
|
||||||
"Idaho": "ID",
|
|
||||||
"Mississippi": "MS",
|
|
||||||
"Washington": "WA",
|
|
||||||
"Nevada": "NV",
|
|
||||||
"Oregon": "OR",
|
|
||||||
"Virginia": "VA",
|
|
||||||
"Wyoming": "WY",
|
|
||||||
"Federated States of Micronesia": "FM",
|
|
||||||
"Kentucky": "KY",
|
|
||||||
"Minnesota": "MN",
|
|
||||||
"Nebraska": "NE",
|
|
||||||
"American Samoa": "AS",
|
|
||||||
"Florida": "FL",
|
|
||||||
"Missouri": "MO",
|
|
||||||
"Texas": "TX",
|
|
||||||
}
|
|
@ -1,3 +1,5 @@
|
|||||||
module weather
|
module weather
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
|
require github.com/joho/godotenv v1.4.0 // indirect
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
||||||
|
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
@ -1,9 +1,15 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# sets enviroment variables on login
|
# creates a hidden file of your location details based on your address, will expand to support addition via zip codes
|
||||||
|
|
||||||
|
if [[ -z $1 ]] ; then
|
||||||
|
# called without args
|
||||||
CURRENT_LOCATION=$(curl --silent http://ip-api.com/csv)
|
CURRENT_LOCATION=$(curl --silent http://ip-api.com/csv)
|
||||||
|
|
||||||
|
STATE_CODE=$(echo "$CURRENT_LOCATION" | cut -d, -f 4)
|
||||||
CITY=$(echo "$CURRENT_LOCATION" | cut -d , -f 6)
|
CITY=$(echo "$CURRENT_LOCATION" | cut -d , -f 6)
|
||||||
LAT=$(echo "$CURRENT_LOCATION" | cut -d , -f 8)
|
LAT=$(echo "$CURRENT_LOCATION" | cut -d , -f 8)
|
||||||
LON=$(echo "$CURRENT_LOCATION" | cut -d , -f 9)
|
LON=$(echo "$CURRENT_LOCATION" | cut -d , -f 9)
|
||||||
|
printf "STATE=%s\nCITY=%s\nLAT=%s\nLON=%s\n" $STATE_CODE $CITY $LAT $LON > "$HOME/.dotfiles/bin/weather/.env.location"
|
||||||
|
fi
|
||||||
|
|
||||||
export LAT LON CITY
|
|
||||||
|
|
||||||
|
Binary file not shown.
@ -1,7 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
source "$HOME/.dotfiles/.priv/key"
|
||||||
# if you get my email banned ill freak out
|
source "$HOME/.dotfiles/bin/weather/.env.location"
|
||||||
API_KEY='60844f78595f66ff8e94df50aed24397'
|
source "$HOME/.dotfiles/bin/weather/.env.weather"
|
||||||
|
# API_KEY=$(cat "$HOME/.dotfiles/bin/weather/.priv/key")
|
||||||
# getting weather
|
# getting weather
|
||||||
|
CUR_TIMESTAMP=$(date +%s)
|
||||||
|
# only update weather every 30 seconds
|
||||||
|
|
||||||
|
if [[ $CUR_TIMESTAMP -gt $EXPIRATION || -z $EXPIRATION ]] ; then
|
||||||
WEATHER=$(curl --silent http://api.openweathermap.org/data/2.5/weather\?lat="$LAT"\&lon="$LON"\&appid="$API_KEY"\&units=imperial)
|
WEATHER=$(curl --silent http://api.openweathermap.org/data/2.5/weather\?lat="$LAT"\&lon="$LON"\&appid="$API_KEY"\&units=imperial)
|
||||||
echo $WEATHER
|
|
||||||
|
TEMP=$(echo $WEATHER | jq -r '.main.temp')
|
||||||
|
HUMIDITY=$(echo $WEATHER | jq -r '.main.humidity')
|
||||||
|
ICON=$(echo $WEATHER | jq -r '.weather[0].icon')
|
||||||
|
EXPIRATION=$(($CUR_TIMESTAMP+30))
|
||||||
|
|
||||||
|
printf 'TEMP=%s\nHUMIDITY=%s\nICON=%s\nEXPIRATION=%s\n' "$TEMP" "$HUMIDITY" "$ICON" "$EXPIRATION" >"$HOME/.dotfiles/bin/weather/.env.weather"
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue