accidently deleted the wrong script
This commit is contained in:
commit
a61df64486
2
.gitignore
vendored
2
.gitignore
vendored
@ -6,5 +6,5 @@ bin/weather/.env*
|
|||||||
*.swp
|
*.swp
|
||||||
bin/startup/*.json
|
bin/startup/*.json
|
||||||
bin/bluebikes/data
|
bin/bluebikes/data
|
||||||
bin/timetracker/timesheets/*
|
bin/timetracker/timesheets
|
||||||
|
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
DATE=1673300954
|
|
||||||
TIME_IN=1673300954
|
|
@ -1,4 +0,0 @@
|
|||||||
Date, Time In, Time Out, Total Time (HH:MM)
|
|
||||||
Fri Jan-06, 2:40pm, 04:30pm, 01:50
|
|
||||||
Mon Jan-09, 12:30pm, 04:33pm, 04:03
|
|
||||||
Mon Jan-09, 04:34pm, 04:49pm, 00:15
|
|
|
@ -1,8 +0,0 @@
|
|||||||
Date, Time In, Time Out, Total Time (HH:MM)
|
|
||||||
Dec-08, 10:18, 11:14, 0:56
|
|
||||||
Dec-08, 12:47, 20:01, 7:14
|
|
||||||
Dec-09, 11:54, 12:38, 0:44
|
|
||||||
Dec-09, 14:56, 19:05, 4:09
|
|
||||||
Dec-13, 13:07, 15:07, 2:00
|
|
||||||
Dec-21, 12:31, 15:38, 3:07
|
|
||||||
Dec-21, 15:38, 17:49, 2:11
|
|
|
@ -1 +0,0 @@
|
|||||||
Date, Time In, Time Out, Total Time (HH:MM)
|
|
|
@ -1,17 +0,0 @@
|
|||||||
Date, Time In, Time Out, Total Time
|
|
||||||
Nov-28, 12:15, 14:30, 2:15
|
|
||||||
Nov-28, 14:36, 15:55, 1:19
|
|
||||||
Nov-29, 13:44, 16:30, 2:46
|
|
||||||
Nov-29, 16:33, 16:56, 0:24
|
|
||||||
Nov-30, 15:19, 19:23, 4:05
|
|
||||||
Dec-01, 12:51, 18:36, 5:44
|
|
||||||
Dec-02, 11:30, 11:32, 0:02
|
|
||||||
Dec-02, 11:33, 12:44, 1:11
|
|
||||||
Dec-02, 15:14, 17:45, 2:31
|
|
||||||
Dec-05, 15:03, 18:26, 3:23
|
|
||||||
Dec-06, 16:30, 20:51, 4:21
|
|
||||||
Dec-06, 20:51, 20:51, 0:01
|
|
||||||
Dec-07, 14:35, 15:44, 1:09
|
|
||||||
Dec-07, 15:44, 15:47, 0:03
|
|
||||||
Dec-07, 15:47, 20:17, 4:30
|
|
||||||
Dec-07, 20:17, 20:40, 0:23
|
|
|
9
bin/weather/.weather
Normal file
9
bin/weather/.weather
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
TEMP=35.06000000000000000000
|
||||||
|
HUMIDITY=63.929305394195
|
||||||
|
ICON=skc
|
||||||
|
LOCATION=
|
||||||
|
ZONE=https://api.weather.gov/zones/forecast/MAZ014
|
||||||
|
CITY="Cambridge"
|
||||||
|
STATE="MA"
|
||||||
|
TOD=night
|
||||||
|
EXPIRATION=1673315272
|
@ -1,40 +0,0 @@
|
|||||||
# day
|
|
||||||
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'
|
|
||||||
# night
|
|
||||||
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'
|
|
60
bin/weather/symbols.json
Normal file
60
bin/weather/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
bin/weather/wttr
168
bin/weather/wttr
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
WEATHER_DIR="${HOME}/.dotfiles/bin/weather"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
Usage: wttr [-s] [-d] [-u] [-i] [-f] [-h]
|
Usage: wttr [-s] [-d] [-u] [-i] [-f] [-h]
|
||||||
@ -7,86 +9,144 @@ Usage: wttr [-s] [-d] [-u] [-i] [-f] [-h]
|
|||||||
Queries the weather and outputs it in a Nerd Font compaitable way
|
Queries the weather and outputs it in a Nerd Font compaitable way
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
-p, --print print the current weather information
|
||||||
-s, --setloc=<LOC> change location used for wttr.in query
|
-s, --setloc=<LOC> change location used for wttr.in query
|
||||||
clears disploc on set
|
will use IP if left blank
|
||||||
-d, --disploc=<LOC> set a location name to display instead of the
|
-d, --disploc=<LOC> show location used in query
|
||||||
location used in wttr.in query
|
|
||||||
-u, --unit={c|f} set the output unit to fahrenheit or celsius
|
|
||||||
-i, --info shows current values of location, unit and
|
|
||||||
disploc if it is set
|
|
||||||
-f, --force force refresh weather data
|
-f, --force force refresh weather data
|
||||||
-h, --help Show this help message
|
-h, --help Show this help message
|
||||||
EOF
|
EOF
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
get_tod() {
|
|
||||||
# sets $TOD
|
|
||||||
hour=$(date +%H)
|
|
||||||
if [[ $hour -gt 21 || $hour -lt 5 ]] ; then # between 9 pm and 5 am
|
|
||||||
TOD="night"
|
|
||||||
else
|
|
||||||
TOD="day"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get_wttr() {
|
get_wttr() {
|
||||||
# gets weather for $LOCATION and stores it into file with timestamp
|
|
||||||
url="https://wttr.in/$LOCATION?format=j2" #json stuff need to fix temp
|
|
||||||
query="{\
|
|
||||||
temp: .current_condition[0].temp_F,\
|
|
||||||
humidity: .current_condition[0].humidity,\
|
|
||||||
conditions: .current_condition[0].weatherCode,\
|
|
||||||
location: .nearest_area[0].areaName[0].value}"
|
|
||||||
|
|
||||||
WTTR=$(curl --silent -fL "$url" | gojq "$query")
|
if [[ -z "$ZONE" || ! -z "$UPDATE" ]] ; then
|
||||||
echo "$WTTR"
|
# getting grid points
|
||||||
#TEMP=$(echo "$WTTR" | gojq -r '.temp_F')
|
url="https://api.weather.gov/points/$LATITUDE,$LONGITUDE"
|
||||||
#HUMIDITY=$(echo "$WTTR" | gojq -r '.humidity')
|
GRID=$(curl --silent -fL "$url")
|
||||||
#CONDITIONS=$(echo "$WTTR" | gojq -r '.weatherDesc[0].value')
|
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() {
|
set_location() {
|
||||||
# updates location of weather query to $new_loc
|
# updates location of weather query to $new_loc, can be empty
|
||||||
echo "TODO"
|
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() {
|
display_location() {
|
||||||
# updates location to display to $disp_loc
|
# updates location to display to $disp_loc
|
||||||
if [[ "$1" == "" ]] ; then
|
printf 'Searching %s, (%s, %s)\n' "$LOCATION" "$CITY" "$STATE"
|
||||||
# no arg given, print current loc
|
|
||||||
echo
|
}
|
||||||
|
|
||||||
|
load_wttr() {
|
||||||
|
# loads and checks weather
|
||||||
|
if [[ ! -f ${WEATHER_DIR}/.weather ]] ; then
|
||||||
|
# file doesnt exist
|
||||||
|
UNITS="F" # defaults to farenheit
|
||||||
|
get_wttr
|
||||||
fi
|
fi
|
||||||
shift
|
|
||||||
echo "TODO"
|
|
||||||
}
|
|
||||||
|
|
||||||
set_units() {
|
# load env
|
||||||
# updates units used to $unit
|
source ${WEATHER_DIR}/.weather
|
||||||
echo "TODO"
|
|
||||||
}
|
|
||||||
|
|
||||||
display_info() {
|
# check for expiration
|
||||||
# prints current config to stdout
|
if [[ $(date +%s) -ge $EXPIRATION ]] ; then
|
||||||
echo "TODO"
|
get_wttr
|
||||||
}
|
fi
|
||||||
|
|
||||||
|
|
||||||
update_wttr() {
|
|
||||||
# checks to see if old weather data is out of date
|
|
||||||
echo "TODO"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_wttr() {
|
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"
|
||||||
|
|
||||||
echo "TODO"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load_wttr
|
||||||
|
|
||||||
while [[ "$1" != "" ]]; do
|
while [[ "$1" != "" ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-h | --help)
|
-h | --help)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
|
-p | --print)
|
||||||
|
print_wttr
|
||||||
|
;;
|
||||||
-s | --setloc)
|
-s | --setloc)
|
||||||
shift
|
shift
|
||||||
new_loc="$1"
|
new_loc="$1"
|
||||||
@ -96,14 +156,6 @@ while [[ "$1" != "" ]]; do
|
|||||||
shift
|
shift
|
||||||
display_location
|
display_location
|
||||||
;;
|
;;
|
||||||
-u | --unit)
|
|
||||||
shift
|
|
||||||
unit="$1"
|
|
||||||
set_units
|
|
||||||
;;
|
|
||||||
-i | --info)
|
|
||||||
display_info
|
|
||||||
;;
|
|
||||||
-f | --force)
|
-f | --force)
|
||||||
get_wttr
|
get_wttr
|
||||||
;;
|
;;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user