diff options
| author | Ryan Schanzenbacher <ryan@rschanz.org> | 2023-05-17 00:21:45 -0400 |
|---|---|---|
| committer | Ryan Schanzenbacher <ryan@rschanz.org> | 2023-05-17 00:21:45 -0400 |
| commit | bf6a91943d2c5852025ed1d1aadb30d83edf0354 (patch) | |
| tree | a7c4efde6a1e2d18919016e9dff81aee8db8f0fe /home-config/waybar/modules/weather.sh | |
| parent | 4fe3a734d104fa1836255b18f8d8bcf4aeaa407f (diff) | |
Added personal channel, starting to add more dotfiles
Diffstat (limited to 'home-config/waybar/modules/weather.sh')
| -rwxr-xr-x | home-config/waybar/modules/weather.sh | 77 |
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 @@ | |||
| 1 | cachedir=~/.cache/rbn | ||
| 2 | cachefile=${0##*/}-$1 | ||
| 3 | |||
| 4 | if [ ! -d $cachedir ]; then | ||
| 5 | mkdir -p $cachedir | ||
| 6 | fi | ||
| 7 | |||
| 8 | if [ ! -f $cachedir/$cachefile ]; then | ||
| 9 | touch $cachedir/$cachefile | ||
| 10 | fi | ||
| 11 | |||
| 12 | # Save current IFS | ||
| 13 | SAVEIFS=$IFS | ||
| 14 | # Change IFS to new line. | ||
| 15 | IFS=$'\n' | ||
| 16 | |||
| 17 | cacheage=$(($(date +%s) - $(stat -c '%Y' "$cachedir/$cachefile"))) | ||
| 18 | if [ $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 | ||
| 23 | fi | ||
| 24 | |||
| 25 | weather=($(cat $cachedir/$cachefile)) | ||
| 26 | |||
| 27 | # Restore IFSClear | ||
| 28 | IFS=$SAVEIFS | ||
| 29 | |||
| 30 | temperature=$(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 | ||
| 35 | case $(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 | ;; | ||
| 73 | esac | ||
| 74 | |||
| 75 | #echo $temp $condition | ||
| 76 | |||
| 77 | echo -e "{\"text\":\""$temperature $condition"\", \"alt\":\""${weather[0]}"\", \"tooltip\":\""${weather[0]}: $temperature ${weather[1]}"\"}" | ||
