summaryrefslogtreecommitdiff
path: root/nws
blob: 581b305f90229eecd3bddec463c9175df5e29d4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash

source ~/.config/nws.conf

colors() {
    NOCOLOR='\033[0m'
    RED='\033[0;31m'
    GREEN='\033[0;32m'
}

cleanup() {
    rm -rf ~/.cache/.county_ids ~/.cache/.weather_forecast ~/.cache/.weather_alerts
}

retrieve_counties() {
    curl -s "https://api.weather.gov/zones?area=${state}" >> ~/.cache/.county_ids
    colors
    count=0
    length=$(echo $(jq '.features | length' ~/.cache/.county_ids) -1 | bc)
    while [ $count -le $length ]
	do
	    echo -e ${GREEN}County: ${NOCOLOR}$(jq '.features['$count'].properties.name' ~/.cache/.county_ids)
	    echo -e ${GREEN}Id: ${NOCOLOR}$(jq '.features['$count'].properties.id' ~/.cache/.county_ids)
	    echo
	    ((count++))
	done
}


get_location() {
    cords=$(curl ipinfo.io/json | jq -r .loc)
}

show_radar() {
    mpv --loop-file=inf "https://radar.weather.gov/ridge/standard/${area1}_loop.gif"
}

show_full_radar() {
    mpv --loop-file=inf "https://radar.weather.gov/ridge/standard/CONUS_loop.gif"
}

show_timing() {
    mpv --loop-file=inf "https://www.weather.gov/images/${area2}/graphicast/image6.png"
}

show_alerts() {
    colors
    curl -s "https://api.weather.gov/alerts/active/zone/${countyId}" >> ~/.cache/.weather_alerts
    length=$(echo $(jq '.features | length' ~/.cache/.weather_alerts) -1 | bc)
    count=0
    while [ $count -le $length ]
	do
	    echo
	    echo
  	    echo --------------------------------------------------------------------------------------------------------------------------------------------
	    echo
	    echo -e ${GREEN}Alert: ${NOCOLOR}$(jq '.features['$count'].properties.headline' ~/.cache/.weather_alerts)
	    echo -e ${GREEN}Starts: ${NOCOLOR}$(jq '.features['$count'].properties.effective' ~/.cache/.weather_alerts)
	    echo -e ${GREEN}Ends: ${NOCOLOR}$(jq '.features['$count'].properties.expires' ~/.cache/.weather_alerts)
	    echo -e ${GREEN}Sent: ${NOCOLOR}$(jq '.features['$count'].properties.sent' ~/.cache/.weather_alerts)
	    echo -e ${GREEN}Severity: ${RED}$(jq '.features['$count'].properties.severity' ~/.cache/.weather_alerts)
	    echo -e ${NOCOLOR}
	    echo -e $(jq '.features['$count'].properties.parameters.NWSheadline' ~/.cache/.weather_alerts)
	    echo -e $(jq '.features['$count'].properties.description' ~/.cache/.weather_alerts)
	    echo -e $(jq '.features['$count'].properties.instruction' ~/.cache/.weather_alerts)
	    echo
	    echo -e ${GREEN}Affected areas: ${NOCOLOR}$(jq '.features['$count'].properties.areaDesc' ~/.cache/.weather_alerts)
	    echo -e ${GREEN}Wind: ${NOCOLOR}$(jq '.features['$count'].properties.windThreat' ~/.cache/.weather_alerts)
	    echo -e ${GREEN}Max Wind Gust: ${NOCOLOR}$(jq '.features['$count'].properties.maxWindGust' ~/.cache/.weather_alerts)
	    echo -e ${GREEN}Hail: ${NOCOLOR}$(jq '.features['$count'].properties.hailThreat' ~/.cache/.weather_alerts)
	    echo -e ${GREEN}Issued by $(jq '.features['$count'].properties.senderName' ~/.cache/.weather_alerts)${NOCOLOR}
	    
	    echo --------------------------------------------------------------------------------------------------------------------------------------------
	    ((count++))
	done
	echo
	echo
	((length++)) # json needs count to start at zero, real amount needs one added
	echo -e ${GREEN}Total alerts: $length${NOCOLOR}
}

count_alerts() {
    curl -s "https://api.weather.gov/alerts/active/zone/${countyId}" >> ~/.cache/.weather_alerts
    length=$(jq '.features | length' ~/.cache/.weather_alerts)
    echo $length
}

show_spc() {
    mpv --loop-file=inf "https://www.spc.noaa.gov/products/activity_loop.gif"
}

get_forecast() {
    get_location
    curl $(curl https://api.weather.gov/points/$cords | jq -r .properties.forecast) >> ~/.cache/.weather_forecast
    echo $(jq .properties.periods[0].name ~/.cache/.weather_forecast | sed 's/"//g'):
    echo ""	
}

help() {
    echo "tw"
    echo "	--full-radar:          shows radar of entire US"
    echo "	--radar:               shows local radar"
    echo "	--spc:	               shows storm predictions"	
    echo "	--retrieve-counties:   shows county ids"
    echo "	-f:                    shows local forecast"
}

cleanup
case $1 in
	"--full-radar") show_full_radar;;
	'--radar') show_radar;;
	'--spc') show_spc;;
	'--retrieve-counties') retrieve_counties;;
	'--ca') count_alerts;;
	'-t') show_timing;;
	'-a') show_alerts | less -R;;
	'-f') get_forecast;;
	'-h') help;;
	"") help;;
esac