summaryrefslogtreecommitdiff
path: root/home-config/waybar/modules/weather.sh
diff options
context:
space:
mode:
Diffstat (limited to 'home-config/waybar/modules/weather.sh')
-rwxr-xr-xhome-config/waybar/modules/weather.sh77
1 files changed, 77 insertions, 0 deletions
diff --git a/home-config/waybar/modules/weather.sh b/home-config/waybar/modules/weather.sh
new file mode 100755
index 0000000..01faffc
--- /dev/null
+++ b/home-config/waybar/modules/weather.sh
@@ -0,0 +1,77 @@
1cachedir=~/.cache/rbn
2cachefile=${0##*/}-$1
3
4if [ ! -d $cachedir ]; then
5 mkdir -p $cachedir
6fi
7
8if [ ! -f $cachedir/$cachefile ]; then
9 touch $cachedir/$cachefile
10fi
11
12# Save current IFS
13SAVEIFS=$IFS
14# Change IFS to new line.
15IFS=$'\n'
16
17cacheage=$(($(date +%s) - $(stat -c '%Y' "$cachedir/$cachefile")))
18if [ $cacheage -gt 1740 ] || [ ! -s $cachedir/$cachefile ]; then
19 data=($(curl -s https://en.wttr.in/$1\?0qnT 2>&1))
20 echo ${data[0]} | cut -f1 -d, > $cachedir/$cachefile
21 echo ${data[1]} | sed -E 's/^.{15}//' >> $cachedir/$cachefile
22 echo ${data[2]} | sed -E 's/^.{15}//' >> $cachedir/$cachefile
23fi
24
25weather=($(cat $cachedir/$cachefile))
26
27# Restore IFSClear
28IFS=$SAVEIFS
29
30temperature=$(echo ${weather[2]} | sed -E 's/([[:digit:]]+)\.\./\1 to /g')
31
32#echo ${weather[1]##*,}
33
34# https://fontawesome.com/icons?s=solid&c=weather
35case $(echo ${weather[1]##*,} | tr '[:upper:]' '[:lower:]') in
36"clear" | "sunny")
37 condition=""
38 ;;
39"partly cloudy")
40 condition=""
41 ;;
42"cloudy")
43 condition=""
44 ;;
45"overcast")
46 condition=""
47 ;;
48"mist" | "fog" | "freezing fog")
49 condition="敖"
50 ;;
51"patchy rain possible" | "patchy light drizzle" | "light drizzle" | "patchy light rain" | "light rain" | "light rain shower" | "rain")
52 condition="殺"
53 ;;
54"moderate rain at times" | "moderate rain" | "heavy rain at times" | "heavy rain" | "moderate or heavy rain shower" | "torrential rain shower" | "rain shower")
55 condition=""
56 ;;
57"patchy snow possible" | "patchy sleet possible" | "patchy freezing drizzle possible" | "freezing drizzle" | "heavy freezing drizzle" | "light freezing rain" | "moderate or heavy freezing rain" | "light sleet" | "ice pellets" | "light sleet showers" | "moderate or heavy sleet showers")
58 condition="流"
59 ;;
60"blowing snow" | "moderate or heavy sleet" | "patchy light snow" | "light snow" | "light snow showers")
61 condition="ﰕ"
62 ;;
63"blizzard" | "patchy moderate snow" | "moderate snow" | "patchy heavy snow" | "heavy snow" | "moderate or heavy snow with thunder" | "moderate or heavy snow showers")
64 condition=""
65 ;;
66"thundery outbreaks possible" | "patchy light rain with thunder" | "moderate or heavy rain with thunder" | "patchy light snow with thunder")
67 condition=""
68 ;;
69*)
70 condition=""
71 echo -e "{\"text\":\""$condition"\", \"alt\":\""${weather[0]}"\", \"tooltip\":\""${weather[0]}: $temperature ${weather[1]}"\"}"
72 ;;
73esac
74
75#echo $temp $condition
76
77echo -e "{\"text\":\""$temperature $condition"\", \"alt\":\""${weather[0]}"\", \"tooltip\":\""${weather[0]}: $temperature ${weather[1]}"\"}"