scripts/waybar/waybar-weather.sh

61 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
URL="https://john.me.tz/weather/weather.json"
curl $URL -o ${HOME}/.local/state/latest_weather 2>/dev/null
RAW="$(cat ${HOME}/.local/state/latest_weather | jq -r '.current | .weather[0]')"
MAIN="$(cat ${HOME}/.local/state/latest_weather | jq -r '.current | .weather[0] | .main')"
DESC="$(cat ${HOME}/.local/state/latest_weather | jq -r '.current | .weather[0] | .description')"
ICON="$(cat ${HOME}/.local/state/latest_weather | jq -r '.current | .weather[0] | .icon')"
WIND="$(cat ${HOME}/.local/state/latest_weather | jq -r '.current | .wind_speed')"
WDEG="$(cat ${HOME}/.local/state/latest_weather | jq -r '.current | .wind_deg')"
TEMP="$(cat ${HOME}/.local/state/latest_weather | jq -r '.current | .feels_like')"
TEMP=$(bc <<<"$TEMP-273.15" | cut -d '.' -f 1)
if [[ $WDEG -gt 337 ]]; then
WDIR=North
elif [[ $WDEG -gt 292 ]]; then
WDIR=North-West
elif [[ $WDEG -gt 247 ]]; then
WDIR=West
elif [[ $WDEG -gt 202 ]]; then
WDIR=South-West
elif [[ $WDEG -gt 157 ]]; then
WDIR=South
elif [[ $WDEG -gt 112 ]]; then
WDIR=South-East
elif [[ $WDEG -gt 67 ]]; then
WDIR=East
elif [[ $WDEG -gt 22 ]]; then
WDIR=North-East
else
WDIR=North
fi
if [[ $ICON == '01d' ]]; then
ICON="☀"
elif [[ $ICON == '01n' ]]; then
ICON="☾"
elif [[ $ICON == '02d' ]]; then
ICON="☁"
elif [[ $ICON == '02n' ]]; then
ICON="☁"
elif [[ $ICON == '03d' ]]; then
ICON="☁"
elif [[ $ICON == '03n' ]]; then
ICON="☁"
elif [[ $ICON == '04d' ]]; then
ICON="☁"
elif [[ $ICON == '04n' ]]; then
ICON="☁"
elif [[ $ICON == '10d' ]]; then
ICON="🌧"
elif [[ $ICON == '10n' ]]; then
ICON="🌧"
else
ICON=""
fi
echo '{"text": "'$ICON''$TEMP'°C", "tooltip": "Condition: '$DESC', Wind: '$WIND'km/h '$WDIR'", "class": "'$MAIN'"}'