moved from dotfiles
This commit is contained in:
commit
b447b8b1d0
3
.env.location
Normal file
3
.env.location
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
CITY=Cambridge
|
||||||
|
LAT=42.3737
|
||||||
|
LON=-71.1284
|
4
.env.weather
Normal file
4
.env.weather
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
TEMP=41.36
|
||||||
|
HUMIDITY=89
|
||||||
|
ICON=04n
|
||||||
|
EXPIRATION=1673568659
|
9
.weather
Normal file
9
.weather
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
TEMP=32.00000000000000000000
|
||||||
|
HUMIDITY=null
|
||||||
|
ICON=ovc
|
||||||
|
LOCATION=
|
||||||
|
ZONE=https://api.weather.gov/zones/forecast/MAZ014
|
||||||
|
CITY=Cambridge
|
||||||
|
STATE=MA
|
||||||
|
TOD=day
|
||||||
|
EXPIRATION=1673634911
|
48
archived/consts
Normal file
48
archived/consts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
"113": "Sunny",
|
||||||
|
"116": "PartlyCloudy",
|
||||||
|
"119": "Cloudy",
|
||||||
|
"122": "VeryCloudy",
|
||||||
|
"143": "Fog",
|
||||||
|
"176": "LightShowers",
|
||||||
|
"179": "LightSleetShowers",
|
||||||
|
"182": "LightSleet",
|
||||||
|
"185": "LightSleet",
|
||||||
|
"200": "ThunderyShowers",
|
||||||
|
"227": "LightSnow",
|
||||||
|
"230": "HeavySnow",
|
||||||
|
"248": "Fog",
|
||||||
|
"260": "Fog",
|
||||||
|
"263": "LightShowers",
|
||||||
|
"266": "LightRain",
|
||||||
|
"281": "LightSleet",
|
||||||
|
"284": "LightSleet",
|
||||||
|
"293": "LightRain",
|
||||||
|
"296": "LightRain",
|
||||||
|
"299": "HeavyShowers",
|
||||||
|
"302": "HeavyRain",
|
||||||
|
"305": "HeavyShowers",
|
||||||
|
"308": "HeavyRain",
|
||||||
|
"311": "LightSleet",
|
||||||
|
"314": "LightSleet",
|
||||||
|
"317": "LightSleet",
|
||||||
|
"320": "LightSnow",
|
||||||
|
"323": "LightSnowShowers",
|
||||||
|
"326": "LightSnowShowers",
|
||||||
|
"329": "HeavySnow",
|
||||||
|
"332": "HeavySnow",
|
||||||
|
"335": "HeavySnowShowers",
|
||||||
|
"338": "HeavySnow",
|
||||||
|
"350": "LightSleet",
|
||||||
|
"353": "LightShowers",
|
||||||
|
"356": "HeavyShowers",
|
||||||
|
"359": "HeavyRain",
|
||||||
|
"362": "LightSleetShowers",
|
||||||
|
"365": "LightSleetShowers",
|
||||||
|
"368": "LightSnowShowers",
|
||||||
|
"371": "HeavySnowShowers",
|
||||||
|
"374": "LightSleetShowers",
|
||||||
|
"377": "LightSleet",
|
||||||
|
"386": "ThunderyShowers",
|
||||||
|
"389": "ThunderyHeavyRain",
|
||||||
|
"392": "ThunderySnowShowers",
|
||||||
|
"395": "HeavySnowShowers",
|
5
archived/go.mod
Normal file
5
archived/go.mod
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module weather
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
require github.com/joho/godotenv v1.4.0 // indirect
|
2
archived/go.sum
Normal file
2
archived/go.sum
Normal file
@ -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=
|
35
archived/location.sh
Executable file
35
archived/location.sh
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# creates a hidden file of your location details based on your address, will expand to support addition via zip codes
|
||||||
|
|
||||||
|
usage() { echo "Usage: $0 [-z zipcode]" 1>&2; exit 1; }
|
||||||
|
|
||||||
|
if [[ $# -eq 0 ]] ; then
|
||||||
|
# called without args
|
||||||
|
CURRENT_LOCATION=$(curl --silent http://ip-api.com/csv)
|
||||||
|
|
||||||
|
CITY=$(echo "$CURRENT_LOCATION" | cut -d , -f 6)
|
||||||
|
LAT=$(echo "$CURRENT_LOCATION" | cut -d , -f 8)
|
||||||
|
LON=$(echo "$CURRENT_LOCATION" | cut -d , -f 9)
|
||||||
|
printf "CITY=%s\nLAT=%s\nLON=%s\n" "$CITY" $LAT $LON > "$HOME/.dotfiles/bin/weather/.env.location"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while getopts "z:" arg; do
|
||||||
|
case ${arg} in
|
||||||
|
z)
|
||||||
|
ZIPCODE=${OPTARG}
|
||||||
|
source "$HOME/.dotfiles/.priv/key"
|
||||||
|
URL="http://api.openweathermap.org/geo/1.0/zip?zip=$ZIPCODE&appid=$API_KEY"
|
||||||
|
LOCATION=$(curl --silent "$URL")
|
||||||
|
CITY=$(echo $LOCATION | jq -r '.name')
|
||||||
|
LAT=$(echo $LOCATION | jq -r '.lat')
|
||||||
|
LON=$(echo $LOCATION | jq -r '.lon')
|
||||||
|
printf "CITY=%s\nLAT=%s\nLON=%s\n" "$CITY" $LAT $LON > "$HOME/.dotfiles/bin/weather/.env.location"
|
||||||
|
# emptying weather buffer
|
||||||
|
>"$HOME/.dotfiles/bin/weather/.env.weather"
|
||||||
|
;;
|
||||||
|
?)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
112
archived/main.go
Normal file
112
archived/main.go
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Weather struct {
|
||||||
|
Temp float64
|
||||||
|
Humidity int
|
||||||
|
Icon rune
|
||||||
|
City string
|
||||||
|
LastPinged int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type weathercode rune
|
||||||
|
|
||||||
|
const (
|
||||||
|
CLEAR_DAY weathercode = '\ue30d'
|
||||||
|
CLEAR_NIGHT weathercode = '\ue32b'
|
||||||
|
PARTLY_CLOUDY_DAY weathercode = '\ue302'
|
||||||
|
PARTLY_CLOUDY_NIGHT weathercode = '\ue379'
|
||||||
|
CLOUDY weathercode = '\ue312'
|
||||||
|
RAIN weathercode = '\ue318'
|
||||||
|
THUNDERSTORM weathercode = '\ue31d'
|
||||||
|
SNOW weathercode = '\ue31a'
|
||||||
|
FOG weathercode = '\ue313'
|
||||||
|
DEGREES_F weathercode = '\ue341'
|
||||||
|
HUMIDITY weathercode = '\ue373'
|
||||||
|
)
|
||||||
|
|
||||||
|
func (w *Weather) String() string {
|
||||||
|
return fmt.Sprintf(" %c %.1f%c %d%c in %s", w.Icon, w.Temp, DEGREES_F, w.Humidity, HUMIDITY, w.City) // Output as ICON ##.#*F ##% in City, ST where the rune is a degree sign
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// getting weather
|
||||||
|
if err := exec.Command(os.ExpandEnv("$HOME/.dotfiles/bin/weather/weather.sh")).Run(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
// get up to date info
|
||||||
|
loc := os.ExpandEnv(fmt.Sprintf("$HOME/.dotfiles/bin/weather/.env.location"))
|
||||||
|
weath := os.ExpandEnv(fmt.Sprintf("$HOME/.dotfiles/bin/weather/.env.weather"))
|
||||||
|
if err := godotenv.Load(weath, loc); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var humidity int
|
||||||
|
var temp float64
|
||||||
|
var err error
|
||||||
|
|
||||||
|
city := os.Getenv("CITY")
|
||||||
|
icon := getIcon(os.Getenv("ICON"))
|
||||||
|
h := os.Getenv("HUMIDITY")
|
||||||
|
t := os.Getenv("TEMP")
|
||||||
|
if h != "" {
|
||||||
|
hum, err := strconv.ParseInt(h, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
humidity = int(hum)
|
||||||
|
}
|
||||||
|
if t != "" {
|
||||||
|
temp, err = strconv.ParseFloat(t, 64)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
weather := &Weather{City: city, Icon: icon, Humidity: humidity, Temp: temp}
|
||||||
|
fmt.Print(weather)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tod(day bool, dayrune weathercode, nightrune weathercode) rune {
|
||||||
|
if day {
|
||||||
|
return rune(dayrune)
|
||||||
|
}
|
||||||
|
return rune(nightrune)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getIcon(code string) rune {
|
||||||
|
weather := strings.Trim(code, "nd") // trimming day or night tag
|
||||||
|
var day bool
|
||||||
|
if strings.Contains(code, "d") {
|
||||||
|
day = true
|
||||||
|
} else {
|
||||||
|
day = false
|
||||||
|
}
|
||||||
|
|
||||||
|
switch weather {
|
||||||
|
case "01":
|
||||||
|
return tod(day, CLEAR_DAY, CLEAR_NIGHT) // clear skies
|
||||||
|
case "02", "03":
|
||||||
|
return tod(day, PARTLY_CLOUDY_DAY, PARTLY_CLOUDY_NIGHT) // small clouds
|
||||||
|
case "04":
|
||||||
|
return rune(CLOUDY) // big clouds with sun
|
||||||
|
case "09", "10":
|
||||||
|
return rune(RAIN)
|
||||||
|
case "11":
|
||||||
|
return rune(THUNDERSTORM)
|
||||||
|
case "13":
|
||||||
|
return rune(SNOW)
|
||||||
|
case "50":
|
||||||
|
return rune(FOG)
|
||||||
|
default:
|
||||||
|
return '\uFFFD' // question mark
|
||||||
|
}
|
||||||
|
}
|
189
archived/new_weather.sh
Executable file
189
archived/new_weather.sh
Executable file
@ -0,0 +1,189 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#source "$HOME/.dotfiles/.priv/key"
|
||||||
|
#source "$HOME/.dotfiles/bin/weather/.env.location"
|
||||||
|
#source "$HOME/.dotfiles/bin/weather/.env.weather"
|
||||||
|
# API_KEY=$(cat "$HOME/.dotfiles/bin/weather/.priv/key")
|
||||||
|
# getting weather
|
||||||
|
CUR_TIMESTAMP=$(date +%s)
|
||||||
|
# only update weather every 30 seconds
|
||||||
|
|
||||||
|
if [[ $CUR_TIMESTAMP -gt $EXPIRATION || -z $EXPIRATION ]] ; then
|
||||||
|
WEATHER=$(curl --silent "http://wttr.in/${LOCATION}?format=j2" | gojq -r '.current_condition[0]')
|
||||||
|
|
||||||
|
echo $WEATHER
|
||||||
|
TEMP=$(echo $WEATHER | gojq -r '.temp_F')
|
||||||
|
HUMIDITY=$(echo $WEATHER | gojq -r '.humidity')
|
||||||
|
ICON=$(echo $WEATHER | gojq -r '.weatherCode')
|
||||||
|
EXPIRATION=$(($CUR_TIMESTAMP+30))
|
||||||
|
echo "TEMP: $TEMP HUMIDITY: $HUMIDITY ICON: $ICON"
|
||||||
|
#printf 'TEMP=%s\nHUMIDITY=%s\nICON=%s\nEXPIRATION=%s\n' "$TEMP" "$HUMIDITY" "$ICON" "$EXPIRATION" >"$HOME/.dotfiles/bin/weather/.env.weather"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
WEATHER_DIR="${HOME}/.dotfiles/bin/weather"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: wttr [-s] [-d] [-u] [-i] [-f] [-h]
|
||||||
|
|
||||||
|
Queries the weather and outputs it in a Nerd Font compaitable way
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-p, --print print the current weather information
|
||||||
|
-s, --setloc=<LOC> change location used for wttr.in query
|
||||||
|
will use IP if left blank
|
||||||
|
-d, --disploc=<LOC> show location used in query
|
||||||
|
-f, --force force refresh weather data
|
||||||
|
-h, --help Show this help message
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
get_wttr() {
|
||||||
|
|
||||||
|
if [[ -z "$ZONE" || ! -z "$UPDATE" ]] ; then
|
||||||
|
# getting grid points
|
||||||
|
url="https://api.weather.gov/points/$LATITUDE,$LONGITUDE"
|
||||||
|
GRID=$(curl --silent -fL "$url")
|
||||||
|
query="{\
|
||||||
|
zone: .properties.forecastZone,\
|
||||||
|
city: .properties.relativeLocation.properties.city,\
|
||||||
|
state: .properties.relativeLocation.properties.state}"
|
||||||
|
|
||||||
|
res=$(echo "$GRID" | gojq "$query")
|
||||||
|
echo "$res"
|
||||||
|
CITY=$(echo "$res" | gojq '.city')
|
||||||
|
STATE=$(echo "$res" | gojq '.state')
|
||||||
|
ZONE=$(echo "$res" | gojq '.zone' | tr -d '"')
|
||||||
|
fi
|
||||||
|
|
||||||
|
WEATHER=$(curl --silent -fL "$ZONE/observations" | gojq '.features[0].properties')
|
||||||
|
query="{\
|
||||||
|
temp: .temperature.value,\
|
||||||
|
humidity: .relativeHumidity.value,\
|
||||||
|
icon: .icon}"
|
||||||
|
|
||||||
|
PARSED=$(echo "$WEATHER" | gojq "$query")
|
||||||
|
TEMP=$(echo "$PARSED" | gojq '.temp')
|
||||||
|
TEMP=$(echo "$TEMP * (9/5) + 32" | bc -l)
|
||||||
|
HUMIDITY=$(echo "$PARSED" | gojq '.humidity')
|
||||||
|
TOD=$(echo "$PARSED" | gojq '.icon' | awk -F / '{print $6}')
|
||||||
|
ICON=$(echo "$PARSED" | gojq '.icon' | awk -F / '{print $7}' | awk -F ? '{print $1}')
|
||||||
|
EXPIRATION=$(($(date +%s) + 60))
|
||||||
|
printf 'TEMP=%s\nHUMIDITY=%s\nICON=%s\nLOCATION=%s\nZONE=%s\nCITY=%s\nSTATE=%s\nTOD=%s\nEXPIRATION=%s\n' "$TEMP" "$HUMIDITY" "$ICON" "$LOCATION" "$ZONE" "$CITY" "$STATE" "$TOD" "$EXPIRATION" > ${WEATHER_DIR}/.weather
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
####
|
||||||
|
# below is WTTR impl, using NWS above
|
||||||
|
####
|
||||||
|
# gets weather for $LOCATION and stores it into file with timestamp
|
||||||
|
# url="https://wttr.in/?format=j1&nonce=$RANDOM"
|
||||||
|
# FULL_WTTR=$(curl --silent -fL "$url")
|
||||||
|
# # parse relevant info
|
||||||
|
# query="{\
|
||||||
|
# temp_F: .current_condition[0].temp_F,\
|
||||||
|
# temp_C: .current_condition[0].temp_C,\
|
||||||
|
# humidity: .current_condition[0].humidity,\
|
||||||
|
# conditions: .current_condition[0].weatherCode,\
|
||||||
|
# location: .nearest_area[0].areaName[0].value,\
|
||||||
|
# sunset: .weather[0].astronomy[0].sunset,\
|
||||||
|
# sunrise: .weather[1].astronomy[0].sunrise}"
|
||||||
|
|
||||||
|
# WTTR=$(echo "$FULL_WTTR" | gojq "$query")
|
||||||
|
# # Parsing info
|
||||||
|
# TEMP=$(echo "$WTTR" | gojq .temp_"$UNITS")
|
||||||
|
# HUMIDITY=$(echo "$WTTR" | gojq '.humidity')
|
||||||
|
# CONDITIONS=$(echo "$WTTR" | gojq '.conditions')
|
||||||
|
# LOCATION=$(echo "$WTTR" | gojq '.location')
|
||||||
|
# # TOD info
|
||||||
|
# SUNSET=$(echo "$WTTR" | gojq '.sunset' | tr -d ' "')
|
||||||
|
# SUNRISE=$(echo "$WTTR" | gojq '.sunrise' | tr -d ' "')
|
||||||
|
# # getting TOD
|
||||||
|
# get_tod
|
||||||
|
|
||||||
|
# # setting symbol
|
||||||
|
# # updating weather info
|
||||||
|
# printf 'UNITS=%s\nTEMP=%s\nHUMIDITY=%s\nCONDITIONS=%s\nLOCATION=%s\nEXPIRATION=%s\nTOD=%s\n' "$UNITS" "$TEMP" "$HUMIDITY" "$CONDITIONS" "$LOCATION" "$EXPIRATION" "$TOD" > ${WEATHER_DIR}/.weather
|
||||||
|
}
|
||||||
|
|
||||||
|
set_location() {
|
||||||
|
# updates location of weather query to $new_loc, can be empty
|
||||||
|
LOCATION="$new_loc"
|
||||||
|
UPDATE="true"
|
||||||
|
|
||||||
|
url="https://v2.wttr.in/$LOCATION?format=j1"
|
||||||
|
query="{\
|
||||||
|
lat: .nearest_area[0].latitude,\
|
||||||
|
lon: .nearest_area[0].longitude}"
|
||||||
|
|
||||||
|
WTTR=$(curl --silent -fL "$url" | gojq "$query")
|
||||||
|
# Grabbing env vars
|
||||||
|
LATITUDE=$(echo "$WTTR" | gojq '.lat' | tr -d ' "')
|
||||||
|
LONGITUDE=$(echo "$WTTR" | gojq '.lon' | tr -d ' "')
|
||||||
|
get_wttr
|
||||||
|
}
|
||||||
|
|
||||||
|
display_location() {
|
||||||
|
# updates location to display to $disp_loc
|
||||||
|
printf 'Searching %s, (%s, %s)\n' "$LOCATION" "$CITY" "$STATE"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
load_wttr() {
|
||||||
|
# loads and checks weather
|
||||||
|
if [[ ! -f ${WEATHER_DIR}/.weather ]] ; then
|
||||||
|
# file doesnt exist
|
||||||
|
UNITS="F" # defaults to farenheit
|
||||||
|
get_wttr
|
||||||
|
fi
|
||||||
|
|
||||||
|
# load env
|
||||||
|
source ${WEATHER_DIR}/.weather
|
||||||
|
|
||||||
|
# check for expiration
|
||||||
|
if [[ $(date +%s) -ge $EXPIRATION ]] ; then
|
||||||
|
get_wttr
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
print_wttr() {
|
||||||
|
# stripping and reformatting quotations
|
||||||
|
query=$(printf '.%s.%s' $TOD $ICON)
|
||||||
|
SYMBOL=$(cat ${WEATHER_DIR}/symbols.json | gojq "$query" | tr -d '"')
|
||||||
|
UNIT=$(echo -e "\ufa04")
|
||||||
|
HUMID_SYMB=$(echo -e "\ue373")
|
||||||
|
printf '%s %.1f%s %0.1f %s in %s, %s\n' "$SYMBOL" "$TEMP" "$UNIT" "$HUMIDITY" "$HUMID_SYMB" "$CITY" "$STATE"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
load_wttr
|
||||||
|
|
||||||
|
while [[ "$1" != "" ]]; do
|
||||||
|
case $1 in
|
||||||
|
-h | --help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
-p | --print)
|
||||||
|
print_wttr
|
||||||
|
;;
|
||||||
|
-s | --setloc)
|
||||||
|
shift
|
||||||
|
new_loc="$1"
|
||||||
|
set_location
|
||||||
|
;;
|
||||||
|
-d | --disploc)
|
||||||
|
shift
|
||||||
|
display_location
|
||||||
|
;;
|
||||||
|
-f | --force)
|
||||||
|
get_wttr
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error: wttr $@"
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
11
archived/symbol_test.sh
Executable file
11
archived/symbol_test.sh
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# prints all symbols that can be used to test output with font
|
||||||
|
echo -e '\ue30d Clear (Day)'
|
||||||
|
echo -e '\ue32b Clear (Night)'
|
||||||
|
echo -e '\ue302 Partly Cloud (Day)'
|
||||||
|
echo -e '\ue379 Partly Cloudy (Night)'
|
||||||
|
echo -e '\ue312 Cloud'
|
||||||
|
echo -e '\ue318 Rain'
|
||||||
|
echo -e '\ue31d Thunderstorm'
|
||||||
|
echo -e '\ue31a Snow'
|
||||||
|
echo -e '\ue313 Fog'
|
56
archived/symbols.go
Normal file
56
archived/symbols.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
var WeatherCodesDay map[string]rune
|
||||||
|
var WeatherCodesNight map[string]rune
|
||||||
|
|
||||||
|
func SymbolTest() {
|
||||||
|
WeatherCodesDay := map[string]rune{
|
||||||
|
"Unkown": '\ue374',
|
||||||
|
"Cloudy": '\ue302',
|
||||||
|
"Fog": '\ue303',
|
||||||
|
"HeavyRain": '\ue318',
|
||||||
|
"HeavyShowers": '\ue318',
|
||||||
|
"HeavySnow": '\ue31a',
|
||||||
|
"HeavySnowShowers": '\ue31a',
|
||||||
|
"LightRain": '\ue308',
|
||||||
|
"LightShowers": '\ue308',
|
||||||
|
"LightSleet": '\ue3aa',
|
||||||
|
"LightSleetShowers": '\ue3aa',
|
||||||
|
"LightSnow": '\ue30a',
|
||||||
|
"LightSnowShowers": '\ue30a',
|
||||||
|
"PartlyCloudy": '\ue37b',
|
||||||
|
"Sunny": '\ue30d',
|
||||||
|
"ThunderyHeavyRain": '\ue31d',
|
||||||
|
"ThunderyShowers": '\ue31d',
|
||||||
|
"ThunderySnowShowers": '\ue365',
|
||||||
|
"VeryCloudy": '\ue312',
|
||||||
|
}
|
||||||
|
|
||||||
|
WeatherCodesNight := map[string]rune{
|
||||||
|
"Unkown": '\ue374',
|
||||||
|
"Cloudy": '\ue37e',
|
||||||
|
"Fog": '\ue346',
|
||||||
|
"HeavyRain": '\ue318',
|
||||||
|
"HeavyShowers": '\ue318',
|
||||||
|
"HeavySnow": '\ue31a',
|
||||||
|
"HeavySnowShowers": '\ue31a',
|
||||||
|
"LightRain": '\ue325',
|
||||||
|
"LightShowers": '\ue325',
|
||||||
|
"LightSleet": '\ue3ac',
|
||||||
|
"LightSleetShowers": '\ue3ac',
|
||||||
|
"LightSnow": '\ue361',
|
||||||
|
"LightSnowShowers": '\ue361',
|
||||||
|
"PartlyCloudy": '\ue379',
|
||||||
|
"Sunny": '\ue32b',
|
||||||
|
"ThunderyHeavyRain": '\ue31d',
|
||||||
|
"ThunderyShowers": '\ue31d',
|
||||||
|
"ThunderySnowShowers": '\ue366',
|
||||||
|
"VeryCloudy": '\ue312',
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range WeatherCodesDay {
|
||||||
|
fmt.Printf("%s: %c %c\n", k, v, WeatherCodesNight[k])
|
||||||
|
}
|
||||||
|
}
|
BIN
archived/weather
Executable file
BIN
archived/weather
Executable file
Binary file not shown.
20
archived/weather.sh
Executable file
20
archived/weather.sh
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
source "$HOME/.dotfiles/.priv/key"
|
||||||
|
source "$HOME/.dotfiles/bin/weather/.env.location"
|
||||||
|
source "$HOME/.dotfiles/bin/weather/.env.weather"
|
||||||
|
# API_KEY=$(cat "$HOME/.dotfiles/bin/weather/.priv/key")
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
echo $WEATHER
|
||||||
|
TEMP=$(echo $WEATHER | gojq -r '.main.temp')
|
||||||
|
HUMIDITY=$(echo $WEATHER | gojq -r '.main.humidity')
|
||||||
|
ICON=$(echo $WEATHER | gojq -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
|
60
symbols.json
Normal file
60
symbols.json
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
{
|
||||||
|
"day": {
|
||||||
|
"Unknown": "",
|
||||||
|
"bkn": "",
|
||||||
|
"wind_bkn": "",
|
||||||
|
"fog": "",
|
||||||
|
"rain": "",
|
||||||
|
"rain_showers": "",
|
||||||
|
"rain_showers_hi": "",
|
||||||
|
"rain_snow": "",
|
||||||
|
"rain": "",
|
||||||
|
"sleet": "",
|
||||||
|
"rain_sleet": "",
|
||||||
|
"fzra": "",
|
||||||
|
"rain_fzra": "",
|
||||||
|
"snow_sleet": "",
|
||||||
|
"snow_frza": "",
|
||||||
|
"snow": "",
|
||||||
|
"sct": "",
|
||||||
|
"few": "",
|
||||||
|
"wind_sct": "",
|
||||||
|
"wind_few": "",
|
||||||
|
"skc": "",
|
||||||
|
"wind_skc": "",
|
||||||
|
"trsa": "",
|
||||||
|
"trsa_sct": "",
|
||||||
|
"trsa_hi": "",
|
||||||
|
"ovc": "",
|
||||||
|
"wind_ovc": ""
|
||||||
|
},
|
||||||
|
"night": {
|
||||||
|
"Unknown": "",
|
||||||
|
"bkn": "",
|
||||||
|
"wind_bkn": "",
|
||||||
|
"fog": "",
|
||||||
|
"rain": "",
|
||||||
|
"rain_showers": "",
|
||||||
|
"rain_showers_hi": "",
|
||||||
|
"rain_snow": "",
|
||||||
|
"rain": "",
|
||||||
|
"rain_showers": "",
|
||||||
|
"rain_showers_hi": "",
|
||||||
|
"sleet": "",
|
||||||
|
"snow_sleet": "",
|
||||||
|
"snow_frza": "",
|
||||||
|
"snow": "",
|
||||||
|
"sct": "",
|
||||||
|
"few": "",
|
||||||
|
"wind_sct": "",
|
||||||
|
"wind_few": "",
|
||||||
|
"skc": "",
|
||||||
|
"wind_skc": "",
|
||||||
|
"trsa": "",
|
||||||
|
"trsa_sct": "",
|
||||||
|
"trsa_hi": "",
|
||||||
|
"ovc": "",
|
||||||
|
"wind_ovc": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
168
weather
Executable file
168
weather
Executable file
@ -0,0 +1,168 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
WEATHER_DIR="${HOME}/.dotfiles/bin/weather"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: wttr [-s] [-d] [-u] [-i] [-f] [-h]
|
||||||
|
|
||||||
|
Queries the weather and outputs it in a Nerd Font compaitable way
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-p, --print print the current weather information
|
||||||
|
-s, --setloc=<LOC> change location used for wttr.in query
|
||||||
|
will use IP if left blank
|
||||||
|
-d, --disploc=<LOC> show location used in query
|
||||||
|
-f, --force force refresh weather data
|
||||||
|
-h, --help Show this help message
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
get_wttr() {
|
||||||
|
|
||||||
|
if [[ -z "$ZONE" || ! -z "$UPDATE" ]] ; then
|
||||||
|
# getting grid points
|
||||||
|
url="https://api.weather.gov/points/$LATITUDE,$LONGITUDE"
|
||||||
|
GRID=$(curl --silent -fL "$url")
|
||||||
|
query="{\
|
||||||
|
zone: .properties.forecastZone,\
|
||||||
|
city: .properties.relativeLocation.properties.city,\
|
||||||
|
state: .properties.relativeLocation.properties.state}"
|
||||||
|
|
||||||
|
res=$(echo "$GRID" | gojq "$query")
|
||||||
|
echo "$res"
|
||||||
|
CITY=$(echo "$res" | gojq '.city')
|
||||||
|
STATE=$(echo "$res" | gojq '.state')
|
||||||
|
ZONE=$(echo "$res" | gojq '.zone' | tr -d '"')
|
||||||
|
fi
|
||||||
|
|
||||||
|
WEATHER=$(curl --silent -fL "$ZONE/observations" | gojq '.features[0].properties')
|
||||||
|
query="{\
|
||||||
|
temp: .temperature.value,\
|
||||||
|
humidity: .relativeHumidity.value,\
|
||||||
|
icon: .icon}"
|
||||||
|
|
||||||
|
PARSED=$(echo "$WEATHER" | gojq "$query")
|
||||||
|
TEMP=$(echo "$PARSED" | gojq '.temp')
|
||||||
|
TEMP=$(echo "$TEMP * (9/5) + 32" | bc -l)
|
||||||
|
HUMIDITY=$(echo "$PARSED" | gojq '.humidity')
|
||||||
|
TOD=$(echo "$PARSED" | gojq '.icon' | awk -F / '{print $6}')
|
||||||
|
ICON=$(echo "$PARSED" | gojq '.icon' | awk -F / '{print $7}' | awk -F ? '{print $1}')
|
||||||
|
EXPIRATION=$(($(date +%s) + 60))
|
||||||
|
printf 'TEMP=%s\nHUMIDITY=%s\nICON=%s\nLOCATION=%s\nZONE=%s\nCITY=%s\nSTATE=%s\nTOD=%s\nEXPIRATION=%s\n' "$TEMP" "$HUMIDITY" "$ICON" "$LOCATION" "$ZONE" "$CITY" "$STATE" "$TOD" "$EXPIRATION" > ${WEATHER_DIR}/.weather
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
####
|
||||||
|
# below is WTTR impl, using NWS above
|
||||||
|
####
|
||||||
|
# gets weather for $LOCATION and stores it into file with timestamp
|
||||||
|
# url="https://wttr.in/?format=j1&nonce=$RANDOM"
|
||||||
|
# FULL_WTTR=$(curl --silent -fL "$url")
|
||||||
|
# # parse relevant info
|
||||||
|
# query="{\
|
||||||
|
# temp_F: .current_condition[0].temp_F,\
|
||||||
|
# temp_C: .current_condition[0].temp_C,\
|
||||||
|
# humidity: .current_condition[0].humidity,\
|
||||||
|
# conditions: .current_condition[0].weatherCode,\
|
||||||
|
# location: .nearest_area[0].areaName[0].value,\
|
||||||
|
# sunset: .weather[0].astronomy[0].sunset,\
|
||||||
|
# sunrise: .weather[1].astronomy[0].sunrise}"
|
||||||
|
|
||||||
|
# WTTR=$(echo "$FULL_WTTR" | gojq "$query")
|
||||||
|
# # Parsing info
|
||||||
|
# TEMP=$(echo "$WTTR" | gojq .temp_"$UNITS")
|
||||||
|
# HUMIDITY=$(echo "$WTTR" | gojq '.humidity')
|
||||||
|
# CONDITIONS=$(echo "$WTTR" | gojq '.conditions')
|
||||||
|
# LOCATION=$(echo "$WTTR" | gojq '.location')
|
||||||
|
# # TOD info
|
||||||
|
# SUNSET=$(echo "$WTTR" | gojq '.sunset' | tr -d ' "')
|
||||||
|
# SUNRISE=$(echo "$WTTR" | gojq '.sunrise' | tr -d ' "')
|
||||||
|
# # getting TOD
|
||||||
|
# get_tod
|
||||||
|
|
||||||
|
# # setting symbol
|
||||||
|
# # updating weather info
|
||||||
|
# printf 'UNITS=%s\nTEMP=%s\nHUMIDITY=%s\nCONDITIONS=%s\nLOCATION=%s\nEXPIRATION=%s\nTOD=%s\n' "$UNITS" "$TEMP" "$HUMIDITY" "$CONDITIONS" "$LOCATION" "$EXPIRATION" "$TOD" > ${WEATHER_DIR}/.weather
|
||||||
|
}
|
||||||
|
|
||||||
|
set_location() {
|
||||||
|
# updates location of weather query to $new_loc, can be empty
|
||||||
|
LOCATION="$new_loc"
|
||||||
|
UPDATE="true"
|
||||||
|
|
||||||
|
url="https://v2.wttr.in/$LOCATION?format=j1"
|
||||||
|
query="{\
|
||||||
|
lat: .nearest_area[0].latitude,\
|
||||||
|
lon: .nearest_area[0].longitude}"
|
||||||
|
|
||||||
|
WTTR=$(curl --silent -fL "$url" | gojq "$query")
|
||||||
|
# Grabbing env vars
|
||||||
|
LATITUDE=$(echo "$WTTR" | gojq '.lat' | tr -d ' "')
|
||||||
|
LONGITUDE=$(echo "$WTTR" | gojq '.lon' | tr -d ' "')
|
||||||
|
get_wttr
|
||||||
|
}
|
||||||
|
|
||||||
|
display_location() {
|
||||||
|
# updates location to display to $disp_loc
|
||||||
|
printf 'Searching %s, (%s, %s)\n' "$LOCATION" "$CITY" "$STATE"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
load_wttr() {
|
||||||
|
# loads and checks weather
|
||||||
|
if [[ ! -f ${WEATHER_DIR}/.weather ]] ; then
|
||||||
|
# file doesnt exist
|
||||||
|
UNITS="F" # defaults to farenheit
|
||||||
|
get_wttr
|
||||||
|
fi
|
||||||
|
|
||||||
|
# load env
|
||||||
|
source ${WEATHER_DIR}/.weather
|
||||||
|
|
||||||
|
# check for expiration
|
||||||
|
if [[ $(date +%s) -ge $EXPIRATION ]] ; then
|
||||||
|
get_wttr
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
print_wttr() {
|
||||||
|
# stripping and reformatting quotations
|
||||||
|
query=$(printf '.%s.%s' $TOD $ICON)
|
||||||
|
SYMBOL=$(cat ${WEATHER_DIR}/symbols.json | gojq "$query" | tr -d '"')
|
||||||
|
UNIT=$(echo -e "\ufa04")
|
||||||
|
HUMID_SYMB=$(echo -e "\ue373")
|
||||||
|
printf '%s %.1f%s %0.1f %s in %s, %s\n' "$SYMBOL" "$TEMP" "$UNIT" "$HUMIDITY" "$HUMID_SYMB" "$CITY" "$STATE"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
load_wttr
|
||||||
|
|
||||||
|
while [[ "$1" != "" ]]; do
|
||||||
|
case $1 in
|
||||||
|
-h | --help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
-p | --print)
|
||||||
|
print_wttr
|
||||||
|
;;
|
||||||
|
-s | --setloc)
|
||||||
|
shift
|
||||||
|
new_loc="$1"
|
||||||
|
set_location
|
||||||
|
;;
|
||||||
|
-d | --disploc)
|
||||||
|
shift
|
||||||
|
display_location
|
||||||
|
;;
|
||||||
|
-f | --force)
|
||||||
|
get_wttr
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error: wttr $@"
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
Loading…
x
Reference in New Issue
Block a user