diff options
author | clarkzjw <[email protected]> | 2022-11-17 10:56:25 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2022-11-17 10:56:25 -0800 |
commit | d2d735742ca61b211c9b48a2209d36395daebcf4 (patch) | |
tree | bda27729a1bbac3ab354a1f10d4885899cdbf967 /dot_config/i3/scripts/executable_openweather-city | |
parent | a6d2e5e6fb9adc84c32e86630b4846b1765c7d77 (diff) | |
download | dotfiles-d2d735742ca61b211c9b48a2209d36395daebcf4.tar.gz |
+ add existing config
Diffstat (limited to 'dot_config/i3/scripts/executable_openweather-city')
-rw-r--r-- | dot_config/i3/scripts/executable_openweather-city | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/dot_config/i3/scripts/executable_openweather-city b/dot_config/i3/scripts/executable_openweather-city new file mode 100644 index 0000000..6ea051c --- /dev/null +++ b/dot_config/i3/scripts/executable_openweather-city | |||
@@ -0,0 +1,43 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | command -v jq >/dev/null 2>&1 || { echo >&2 "Program 'jq' required but it is not installed. | ||
4 | Aborting."; exit 1; } | ||
5 | command -v wget >/dev/null 2>&1 || { echo >&2 "Program 'wget' required but is not installed. | ||
6 | Aborting."; exit 1; } | ||
7 | |||
8 | # To use this script you need to create an API key here https://home.openweathermap.org | ||
9 | # You need to put your Open Weather APIKEY here: | ||
10 | APIKEY="keykey" | ||
11 | # find your City ID here: https://openweathermap.org/ | ||
12 | # search for your city and copy the ID from the URL inside the browser. | ||
13 | CITY_ID="idid" | ||
14 | URL="http://api.openweathermap.org/data/2.5/weather?id=${CITY_ID}&units=metric&APPID=${APIKEY}" | ||
15 | |||
16 | WEATHER_RESPONSE=$(wget -qO- "${URL}") | ||
17 | |||
18 | WEATHER_CONDITION=$(echo $WEATHER_RESPONSE | jq '.weather[0].main' | sed 's/"//g') | ||
19 | WEATHER_TEMP=$(echo $WEATHER_RESPONSE | jq '.main.temp') | ||
20 | WIND_DIR=$( echo "$WEATHER_RESPONSE" | jq '.wind.deg') | ||
21 | WIND_SPEED=$( echo "$WEATHER_RESPONSE" | jq '.wind.speed') | ||
22 | |||
23 | WIND_SPEED=$(awk "BEGIN {print 60*60*$WIND_SPEED/1000}") | ||
24 | WIND_DIR=$(awk "BEGIN {print int(($WIND_DIR % 360)/22.5)}") | ||
25 | DIR_ARRAY=( N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW N ) | ||
26 | WIND_DIR=${DIR_ARRAY[WIND_DIR]} | ||
27 | |||
28 | case $WEATHER_CONDITION in | ||
29 | 'Clouds') | ||
30 | WEATHER_ICON="" | ||
31 | ;; | ||
32 | 'Rain') | ||
33 | WEATHER_ICON="" | ||
34 | ;; | ||
35 | 'Snow') | ||
36 | WEATHER_ICON="" | ||
37 | ;; | ||
38 | *) | ||
39 | WEATHER_ICON="" | ||
40 | ;; | ||
41 | esac | ||
42 | |||
43 | echo "${WEATHER_ICON} ${WEATHER_TEMP}°C: ${WIND_SPEED} km/h ${WIND_DIR}" | ||