diff options
Diffstat (limited to 'dot_config/i3/scripts/executable_openweather')
-rw-r--r-- | dot_config/i3/scripts/executable_openweather | 93 |
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 | |||
4 | temps=("#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 | |||
6 | command -v jq >/dev/null 2>&1 || { echo >&2 "Program 'jq' required but it is not installed. | ||
7 | Aborting."; exit 1; } | ||
8 | command -v wget >/dev/null 2>&1 || { echo >&2 "Program 'wget' required but is not installed. | ||
9 | Aborting."; 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: | ||
13 | APIKEY="keykeykey" | ||
14 | # And get your Latitute and Longitudes to put in here: | ||
15 | LAT="XX.XXXX" | ||
16 | LON="XX.XXXX" | ||
17 | URL="http://api.openweathermap.org/data/2.5/onecall?lat=${LAT}&lon=${LON}&units=metric&exclude=minutely,hourly,daily&APPID=${APIKEY}" | ||
18 | WEATHER_RESPONSE=$(wget -qO- "${URL}") | ||
19 | |||
20 | WEATHER_CONDITION=$(echo "$WEATHER_RESPONSE" | jq '.current.weather[0].main' | sed 's/"//g') | ||
21 | WEATHER_TEMP=$(echo "$WEATHER_RESPONSE" | jq '.current.feels_like') | ||
22 | WEATHER_INT=${WEATHER_TEMP%.*} | ||
23 | |||
24 | TIME_NOW=$( echo "$WEATHER_RESPONSE" | jq '.current.dt') | ||
25 | SUNRISE=$( echo "$WEATHER_RESPONSE" | jq '.current.sunrise') | ||
26 | SUNSET=$( echo "$WEATHER_RESPONSE" | jq '.current.sunset') | ||
27 | DESCRIPTION=$( echo "$WEATHER_RESPONSE" | jq '.current.weather[0].description' | sed 's/"//g') | ||
28 | WEATHER_ALERT=$( echo "$WEATHER_RESPONSE" | jq '.alerts[0].event' | sed 's/"//g') | ||
29 | DAYTIME="n" | ||
30 | |||
31 | if [[ "$TIME_NOW" > "$SUNRISE" ]] && [[ "$TIME_NOW" < "$SUNSET" ]]; then | ||
32 | DAYTIME="d" | ||
33 | fi | ||
34 | |||
35 | case $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 | ;; | ||
69 | esac | ||
70 | |||
71 | WEATHER_COLOR="#FFFFFF" | ||
72 | if [ "$WEATHER_INT" -lt "-11" ]; then | ||
73 | WEATHER_COLOR="#0000FF" | ||
74 | elif [ "$WEATHER_INT" -gt 35 ]; then | ||
75 | WEATHER_COLOR="#FF0000" | ||
76 | else | ||
77 | WEATHER_INT=$(( WEATHER_INT + 11 )) | ||
78 | WEATHER_COLOR="${temps[$WEATHER_INT]}" | ||
79 | fi | ||
80 | |||
81 | full_text="${WEATHER_ICON} ${WEATHER_TEMP}°C: ${DESCRIPTION} " | ||
82 | if [ "$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} " | ||
88 | fi | ||
89 | |||
90 | |||
91 | echo "${full_text}" | ||
92 | echo "${WEATHER_TEMP}°C " | ||
93 | echo "${WEATHER_COLOR}" | ||