-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweather-summary
More file actions
248 lines (227 loc) · 6.79 KB
/
weather-summary
File metadata and controls
248 lines (227 loc) · 6.79 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
# source: https://github.com/polybar/polybar-scripts/tree/master/polybar-scripts/openweathermap-fullfeatured
# this is HEAVILY modified. No Awesome fonts; sorry.
# You will need
# get_weather --> in this repo. This actually pulls in the weather
# genius
# xmllint --> you get more weather with XML
get_icon() {
case $1 in
# Icons for weather-icons
01d) icon="\uF00D";;
01n) icon="\uF02E";;
02d) icon="\uF002";;
02n) icon="\uF086";;
03*) icon="\uF041";;
04*) icon="\uF013";;
09*) icon="\uF019";;
10d) icon="\uF008";;
10n) icon="\uF028";;
11*) icon="\uF016";;
13*) icon="\uF064";;
50*) icon="\uF014";;
*) icon="\uF07B";;
esac
echo -e $icon
}
get_Beaufort_icon(){
case "$1" in
"Calm") bs="\uF0B7";;
"Light Air") bs="\uF0B8";;
"Light breeze"|"Light Breeze") bs="\uF0B9";;
"Gentle Breeze") bs="\uF0BA";;
"Moderate breeze"|"Moderate Breeze") bs="\uF0BB";;
"Fresh Breeze") bs="\uF0BC";;
"Strong breeze"|"Strong Breeze") bs="\uF0BD";;
"Near Gale"|"High wind, near gale") bs="\uF0BE";;
"Gale") bs="\uF0BF";;
"Strong Gale"|"Severe Gale") bs="\uF0C0";;
"Storm") bs="\uF0C1";;
"Violent Storm") bs="\uF0C2";;
"Hurricane") bs="\uF0C3";;
esac
echo -e $bs
}
#########################################################################
# openweathermap does not use 'Light Air'; uses 'Severe Gale' rather #
# than 'Strong Gale'; and has 'High wind, near gale' for 'Near Gale.' #
# I can't find openweathermap's classification anywhere else, so I did #
# not use it. The below function uses the original classifcations and #
# works with m.p.h. ($wsmph) #
#########################################################################
trueBeaufort(){
sw=$1
if [[ $sw -lt 1 ]]; then
beaufort="Calm"
elif [[ $sw -ge 1 && $sw -le 3 ]]; then
beaufort="Light Air"
elif [[ $sw -ge 4 && $sw -le 7 ]]; then
beaufort="Light Breeze"
elif [[ $sw -ge 8 && $sw -le 12 ]]; then
beaufort="Gentle Breeze"
elif [[ $sw -ge 13 && $sw -le 18 ]]; then
beaufort="Moderate Breeze"
elif [[ $sw -ge 19 && $sw -le 24 ]]; then
beaufort="Fresh Breeze"
elif [[ $sw -ge 25 && $sw -le 31 ]]; then
beaufort="Strong Breeze"
elif [[ $sw -ge 32 && $sw -le 38 ]]; then
beaufort="Near Gale"
elif [[ $sw -ge 39 && $sw -le 46 ]]; then
beaufort="Gale"
elif [[ $sw -ge 47 && $sw -le 54 ]]; then
beaufort="Strong Gale"
elif [[ $sw -ge 55 && $sw -le 63 ]]; then
beaufort="Storm"
elif [[ $sw -ge 64 && $sw -le 72 ]]; then
beaufort="Violent Storm"
else beaufort="Hurricane"
fi
echo $beaufort
}
#sunrise and sunset icons
R=""
r=""
tempf(){
genius --exec="round((($1 * 9)/5) + 32)"
}
tempk(){
genius --exec="$1 - 273.15"
}
mph(){
genius --exec="round(($1 * 2.2369362920544))"
}
kph(){
genius --exec="round(($1 * 3.6))"
}
inches(){
genius --exec="round(($1 / 25.4))"
}
pHg(){
genius --exec="round(($1 * 0.75))"
}
tz=$(xmllint --xpath 'string(//timezone)' ~/.local/share/wm.xml)
tempc=$(xmllint --xpath 'string(//temperature/@value)' ~/.local/share/wm.xml)
fltemp=$(xmllint --xpath 'string(//feels_like/@value)' ~/.local/share/wm.xml)
maxtemp=$(xmllint --xpath 'string(//temperature/@max)' ~/.local/share/wm.xml)
mintemp=$(xmllint --xpath 'string(//temperature/@min)' ~/.local/share/wm.xml)
_S=$(date +"%s" -d "$(xmllint --xpath 'string(//sun/@rise)' ~/.local/share/wm.xml)")
S=$(genius --exec="$_S + $tz")
S=$(date -Iseconds -d "@$S")
_s=$(date +"%s" -d "$(xmllint --xpath 'string(//sun/@set)' ~/.local/share/wm.xml)")
s=$(genius --exec="$_s + $tz")
s=$(date -Iseconds -d "@$s")
t=$(genius --exec="round($tempc)")
f=$(genius --exec="round($fltemp)")
l=$(genius --exec="round($mintemp)")
h=$(genius --exec="round($maxtemp)")
w=$(xmllint --xpath 'string(//wind/speed/@value)' ~/.local/share/wm.xml)
B="$(trueBeaufort $(mph "$w"))"
b=$(get_Beaufort_icon "$B")
D="$(xmllint --xpath 'string(//wind/direction/@code)' ~/.local/share/wm.xml)"
d=$(xmllint --xpath 'string(//wind/direction/@value)' ~/.local/share/wm.xml)
T="$(xmllint --xpath 'string(//weather/@value)' ~/.local/share/wm.xml)"
P=$(xmllint --xpath 'string(//precipitation/@mode)' ~/.local/share/wm.xml)
p=$(xmllint --xpath 'string(//precipitation/@value)' ~/.local/share/wm.xml)
if [[ -z $p ]]; then
declare -i p=0
fi
C=$(xmllint --xpath 'string(//city/@name)' ~/.local/share/wm.xml)
c=$(xmllint --xpath 'string(//country)' ~/.local/share/wm.xml)
u=$(xmllint --xpath 'string(//pressure/@value)' ~/.local/share/wm.xml)
H=$(xmllint --xpath 'string(//humidity/@value)' ~/.local/share/wm.xml)
I=$(get_icon "$(xmllint --xpath 'string(//weather/@icon)' ~/.local/share/wm.xml)")
m="$(moonphase -i)"
M="$(moonphase -t)"
while getopts "?PHmSkMi42CFKf:" opt; do
case "$opt" in
P)
u="$u hPa"
;;
H)
u="$(pHg $u) mmHg"
;;
S)
w="$w m\/s"
;;
m)
w="$(mph $w) m.p.h."
;;
k)
w="$(kph $w) km\/h"
;;
M)
p="$p mm"
;;
i)
p="$(inches "$p")"
# units="in."
;;
C)
t="$t°C"
l="$h°C"
h="$h°C"
f="$f°C"
;;
F)
t="$(tempf $t)°F"
l="$(tempf $l)°F"
h="$(tempf $h)°F"
f="$(tempf $f)°F"
;;
K)
t="$(tempk $t) K"
l="$(tempk $l) K"
h="$(tempk $h) K"
f="$(tempk $f) K"
;;
2)
S=$(date +"%l:%M%P" -d "$S")
s=$(date +"%l:%M%P" -d "$s")
;;
4)
S=$(date +"%H:%M" -d "$S")
s=$(date +"%H:%M" -d "$s")
;;
f)
formatted=$OPTARG
;;
?)
cat <<HELPTEXT
weather-summary [UNIT_OPTIONS] -f "[FORMAT_STRING]"
UNIT_OPTIONS (all optional, units default to metric system and 24h clock):
-C | -F | -K temperature units (Celsius, Fahrenheit, Kelvin)
-P | -H pressure units (hPa, mmHg)
-S | -m | -k speed units (m/s, m.p.h., km/h)
-M | -i precipitation measurement units (mm, in)
-4 | -2 sunrise/sunset time format (24h, 12h)
FORMAT FLAG:
-f "FORMAT" where
%C = location
%c = country
%T = description
%I = description icon
%S = sunrise time
%s = sunset time
%R = sunrise icon
%r = sunset icon
%t = temperature
%h = maximum temperature
%l = minimum temperature
%H = humidity
%f = "feels like" temperature
%w = wind speed
%D = wind compass direction
%d = wind direction in degrees
%P = preciptation
%p = precipation measurement
%u = pressure
%B = Beaufort wind scale
%b = Beaufort wind scale icon
%M = moon phase
%m = moon phase icon
HELPTEXT
;;
esac
done
echo $formatted | sed -r -e "s/\%C/$C/g" -e "s/\%c/$c/g" -e "s/\%H/$H/g" -e "s/\%u/$u/g" -e "s/\%t/$t/g" -e "s/\%l/$l/g" -e "s/\%h/$h/g" -e "s/\%f/$f/g" -e "s/\%R/$R/g" -e "s/\%r/$r/g" -e "s/\%S/$S/g" -e "s/\%s/$s/g" -e "s/\%w/$w/g" -e "s/\%P/$P/g" -e "s/\%p/$p/g" -e "s/\%d/$d/g" -e "s/\%D/$D/g" -e "s/\%B/$B/g" -e "s/\%b/$b/g" -e "s/\%T/$T/g" -e "s/\%I/$I/g" -e "s/\%M/$M/g" -e "s/\%m/$m/g"