aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2022-11-17 10:56:25 -0800
committerclarkzjw <[email protected]>2022-11-17 10:56:25 -0800
commitd2d735742ca61b211c9b48a2209d36395daebcf4 (patch)
treebda27729a1bbac3ab354a1f10d4885899cdbf967 /dot_config/i3/scripts/executable_openweather
parenta6d2e5e6fb9adc84c32e86630b4846b1765c7d77 (diff)
downloaddotfiles-d2d735742ca61b211c9b48a2209d36395daebcf4.tar.gz
+ add existing config
Diffstat (limited to 'dot_config/i3/scripts/executable_openweather')
-rw-r--r--dot_config/i3/scripts/executable_openweather93
1 files changed, 93 insertions, 0 deletions
diff --git a/dot_config/i3/scripts/executable_openweather b/dot_config/i3/scripts/executable_openweather
new file mode 100644
index 0000000..c51f9d3
--- /dev/null
+++ b/dot_config/i3/scripts/executable_openweather
@@ -0,0 +1,93 @@
1#!/usr/bin/env bash
2# Edited by Andreas Lindlbauer <[email protected]>
3
4temps=("#0600FF" "#0500FF" "#0400FF" "#0300FF" "#0200FF" "#0100FF" "#0000FF" "#0002FF" "#0012FF" "#0022FF" "#0032FF" "#0044FF" "#0054FF" "#0064FF" "#0074FF" "#0084FF" "#0094FF" "#00A4FF" "#00B4FF" "#00C4FF" "#00D4FF" "#00E4FF" "#00FFF4" "#00FFD0" "#00FFA8" "#00FF83" "#00FF5C" "#00FF36" "#00FF10" "#17FF00" "#3EFF00" "#65FF00" "#B0FF00" "#FDFF00" "#FFF000" "#FFDC00" "#FFC800" "#FFB400" "#FFA000" "#FF8C00" "#FF7800" "#FF6400" "#FF5000" "#FF3C00" "#FF2800" "#FF1400" "#FF0000")
5
6command -v jq >/dev/null 2>&1 || { echo >&2 "Program 'jq' required but it is not installed.
7Aborting."; exit 1; }
8command -v wget >/dev/null 2>&1 || { echo >&2 "Program 'wget' required but is not installed.
9Aborting."; exit 1; }
10
11# To use this script you need to create an API key here https://home.openweathermap.org
12# You need to put your Open Weather APIKEY here:
13APIKEY="keykeykey"
14# And get your Latitute and Longitudes to put in here:
15LAT="XX.XXXX"
16LON="XX.XXXX"
17URL="http://api.openweathermap.org/data/2.5/onecall?lat=${LAT}&lon=${LON}&units=metric&exclude=minutely,hourly,daily&APPID=${APIKEY}"
18WEATHER_RESPONSE=$(wget -qO- "${URL}")
19
20WEATHER_CONDITION=$(echo "$WEATHER_RESPONSE" | jq '.current.weather[0].main' | sed 's/"//g')
21WEATHER_TEMP=$(echo "$WEATHER_RESPONSE" | jq '.current.feels_like')
22WEATHER_INT=${WEATHER_TEMP%.*}
23
24TIME_NOW=$( echo "$WEATHER_RESPONSE" | jq '.current.dt')
25SUNRISE=$( echo "$WEATHER_RESPONSE" | jq '.current.sunrise')
26SUNSET=$( echo "$WEATHER_RESPONSE" | jq '.current.sunset')
27DESCRIPTION=$( echo "$WEATHER_RESPONSE" | jq '.current.weather[0].description' | sed 's/"//g')
28WEATHER_ALERT=$( echo "$WEATHER_RESPONSE" | jq '.alerts[0].event' | sed 's/"//g')
29DAYTIME="n"
30
31if [[ "$TIME_NOW" > "$SUNRISE" ]] && [[ "$TIME_NOW" < "$SUNSET" ]]; then
32 DAYTIME="d"
33fi
34
35case $WEATHER_CONDITION in
36 'Clouds')
37 if [ "$DAYTIME" == "d" ]; then
38 WEATHER_ICON=""
39 else
40 WEATHER_ICON=""
41 fi
42 ;;
43 'Rain')
44 WEATHER_ICON=""
45 ;;
46 'Drizzle')
47 if [ "$DAYTIME" == "d" ]; then
48 WEATHER_ICON=""
49 else
50 WEATHER_ICON=""
51 fi
52 ;;
53 'Thunderstorm')
54 WEATHER_ICON=""
55 ;;
56 'Snow')
57 WEATHER_ICON=""
58 ;;
59 'Clear')
60 if [ "$DAYTIME" == "d" ]; then
61 WEATHER_ICON=""
62 else
63 WEATHER_ICON=""
64 fi
65 ;;
66 *)
67 WEATHER_ICON="🌫"
68 ;;
69esac
70
71WEATHER_COLOR="#FFFFFF"
72if [ "$WEATHER_INT" -lt "-11" ]; then
73 WEATHER_COLOR="#0000FF"
74elif [ "$WEATHER_INT" -gt 35 ]; then
75 WEATHER_COLOR="#FF0000"
76else
77 WEATHER_INT=$(( WEATHER_INT + 11 ))
78 WEATHER_COLOR="${temps[$WEATHER_INT]}"
79fi
80
81full_text="${WEATHER_ICON} ${WEATHER_TEMP}°C: ${DESCRIPTION} "
82if [ "$WEATHER_ALERT" != "null" ]; then
83 WARN_START=$(echo "$WEATHER_RESPONSE" | jq '.alerts[0].start')
84 WARN_END=$(echo "$WEATHER_RESPONSE" | jq '.alerts[0].end')
85 WARN_START=$(date -d @"$WARN_START" +%a_%k:%M)
86 WARN_END=$(date -d @"$WARN_END" +%a_%k:%M)
87 full_text="${WEATHER_ICON} ${WEATHER_TEMP}°C: ${DESCRIPTION}  ${WEATHER_ALERT} from ${WARN_START} to ${WARN_END}  "
88fi
89
90
91echo "${full_text}"
92echo "${WEATHER_TEMP}°C "
93echo "${WEATHER_COLOR}"
Powered by cgit v1.2.3 (git 2.41.0)