This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather
executable file
·115 lines (98 loc) · 2.68 KB
/
weather
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
#!/bin/dash
# A wrapper around https://github.com/chubin/wttr.in
WEATHER_CACHE_DIR="/home/alex/.cache/weather"
CACHEFILE=$WEATHER_CACHE_DIR"/current_weather.png"
CACHEFILE_WHITE=$WEATHER_CACHE_DIR"/current_weather_white.png"
CACHE_ONELINE=$WEATHER_CACHE_DIR"/current_weather_oneline.txt"
TIME=""
OPTION=$2
screen_resolution=$( xrandr | awk '/\*/ { print $1 }' )
screen_x=$(echo $screen_resolution | cut -d'x' -f1)
screen_y=$(echo $screen_resolution | cut -d'x' -f2)
SHOW_IMAGE_X=$((screen_x - 400))
SHOW_IMAGE_Y=$((35))
usage () {
echo "Usage: $0 (help|update|show|get|reload|full|dark|white|text) [:help|p|q]"
echo " help : show this page
show : show picture according to time
get : get image from wttr.in
reload : get and show
full : curl wttr.in [:help|p|q]
white : show white picture
dark : show dark picture
text : print one line text
clear : clear text cache
update : update awesome wibar
example: weather f 'Kitchener_0pq'
weather f moon
" >&2
exit 0
}
dark_or_white() {
h=$(date +%H)
if [ $h -lt 7 -o $h -gt 19 ]; then
echo it\'s late
TIME="dark"
else
echo good day
TIME="white"
fi
}
onlyprinttext() {
info=$(cat $CACHE_ONELINE)
case $info in
*DOCTYPE*) echo " n/a";;
*) echo $info ;;
esac
}
negate_image() {
convert $CACHEFILE -negate $CACHEFILE_WHITE
}
get_image() {
curl -s 'wttr.in/Kitchener_0pq.png' > $CACHEFILE
curl -s 'wttr.in/?format=%c+%t' > $CACHE_ONELINE
notify-send "🌤 weather""Cache update"
negate_image
}
print_detail() {
echo curl -s "wttr.in/"$OPTION
curl -s "wttr.in"/$OPTION
}
show_image() {
if [ ! -e $CACHEFILE ]; then
get_image
fi
echo showing $1
if [ ! $1 = "white" ]; then
n30f -x $SHOW_IMAGE_X -y $SHOW_IMAGE_Y $CACHEFILE -c "sxiv $CACHEFILE" &
else
n30f -x $SHOW_IMAGE_X -y $SHOW_IMAGE_Y $CACHEFILE_WHITE -c "sxiv $CACHEFILE_WHITE" &
fi
pid_num=$!
if [ $? -eq 0 ]; then
sleep 10s && kill $pid_num &
fi
}
update_awesomewm() {
oneline=`head -1 $CACHE_ONELINE`
echo "myweather.text = \"$oneline\"" | awesome-client
}
# main
if [ ! -d $WEATHER_CACHE_DIR ]; then
mkdir $WEATHER_CACHE_DIR
get_image && update_awesomewm
fi
case "$1" in
h|-h*|--h*) usage ;;
show|s) dark_or_white; show_image $TIME;;
dark|d) show_image "dark";;
white|w) show_image "white";;
get|g) get_image ;;
update|u) update_awesomewm ;;
reload|r) get_image && dark_or_white && show_image && update_awesomewm;;
full|f) print_detail; OPTION=$2;;
negate|n) negate_image;;
text|t) onlyprinttext;;
*) onlyprinttext; usage;;
esac
# vim: filetype=sh