changing weather script to support wttr.in
parent
2e087b18c0
commit
60972cc069
@ -1,15 +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
|
||||
|
||||
if [[ -z $1 ]] ; then
|
||||
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)
|
||||
|
||||
STATE_CODE=$(echo "$CURRENT_LOCATION" | cut -d, -f 4)
|
||||
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 "STATE=%s\nCITY=%s\nLAT=%s\nLON=%s\n" $STATE_CODE $CITY $LAT $LON > "$HOME/.dotfiles/bin/weather/.env.location"
|
||||
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
|
||||
|
||||
|
@ -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": '\ue365',
|
||||
"VeryCloudy": '\ue312',
|
||||
}
|
||||
|
||||
for k, v := range WeatherCodesDay {
|
||||
fmt.Printf("%s: %c %c\n", k, v, WeatherCodesNight[k])
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue