-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-weather.sh
executable file
·73 lines (64 loc) · 1.85 KB
/
get-weather.sh
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
#!/usr/bin/env bash
# variables --------------------------------------------------------------------
cache_path="$HOME/.cache/weather"
# functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function get_all() {
jq -r . "$cache_path"
}
function get_value() {
filter="$1"
jq -r "$filter" "$cache_path"
}
function get_location() {
place=$(jq -r .name "$cache_path")
state=$(jq -r .sys.country "$cache_path")
echo "${place}, ${state}"
}
function get_icon() {
conditions=$(get_value ".weather[0].main")
case $conditions in
Thunderstorm) echo 🌩 ;;
Drizzle) echo 🌧 ;;
Rain) echo 🌧 ;;
Snow) echo ❄ ;;
Atmosphere) echo 🌁 ;;
Clear) echo ☀ ;;
Clouds) echo ⛅ ;;
Mist) echo 🌫 ;;
Overcast) echo ☁ ;;
Haze) echo 🌫 ;;
*) echo "❓$conditions" ;;
esac
}
function get_summary() {
icon=$(get_icon)
status=$(get_value ".weather[0].description")
humidity=$(get_value ".main.humidity")
pressure=$(get_value ".main.pressure")
temp_float=$(get_value ".main.temp")
temp_int=$(printf "%.0f" "$temp_float")
echo "${icon} ${status}"
echo "🌡 ${temp_int}°C"
echo "🌢 ${humidity}%"
echo "🡇 ${pressure} hPa"
}
# FIXME not currently used with anything
function get_icon_path() {
icons_path="/usr/share/icons/Papirus-Dark/symbolic/status"
icon="clear"
echo "${icons_path}/weather-${icon}-symbolic.svg"
}
# execution ********************************************************************
case $1 in
'') get_all ;;
summary) get_summary ;;
status) get_value ".weather[0].description" ;;
temp) get_value ".main.temp" ;;
humidity) get_value ".main.humidity" ;;
pressure) get_value ".main.pressure" ;;
wind) get_value ".wind.speed" ;;
location) get_location ;;
icon) get_icon ;;
icon_path) get_icon_path ;;
*) get_value ".$1" ;;
esac