46 lines
2.0 KiB
Bash
46 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
set -Eeu -o pipefail
|
|
|
|
VALUE_COLOR=${color:-$(xrescat i3xrocks.value.color "#D8DEE9")}
|
|
VALUE_FONT=${font:-$(xrescat i3xrocks.value.font "Source Code Pro Medium 13")}
|
|
BUTTON="${button:-}"
|
|
|
|
# Information on the various formats: https://github.com/chubin/wttr.in
|
|
VALUE_WEATHER_FORMAT=${weather_format:-$(xrescat i3xrocks.weather.format "1")}
|
|
VALUE_WEATHER_FORMAT="?format=${VALUE_WEATHER_FORMAT}"
|
|
# all format options: "https://wttr.in?format=%l:+%c+%f+%h+%p+%P+%m+%w+%S+%s"
|
|
VALUE_SUNSET_SUNRISE_FORMAT="?format=%S-%s%20%m+"
|
|
|
|
# Determine units to use for temperature
|
|
# We don't supply a default here because wttr.in is "smart" enough to choose for us
|
|
WEATHER_UNIT=${weather_unit:-$(xrescat i3xrocks.weather.units "")}
|
|
if [ -n "${WEATHER_UNIT}" ]; then
|
|
WEATHER_UNIT="&${WEATHER_UNIT}"
|
|
fi
|
|
|
|
# Defaults to IP address location
|
|
VALUE_WEATHER_LOCATION=${weather_location:-$(xrescat i3xrocks.weather.location "Pärnu")}
|
|
VALUE_WEATHER_ERROR_MESSAGE=${error_message:-$(xrescat i3xrocks.weather.error_message $'\u26D4')}
|
|
VALUE_FETCH_WEATHER_URL="https://wttr.in/${VALUE_WEATHER_LOCATION}${VALUE_WEATHER_FORMAT}${WEATHER_UNIT}"
|
|
#echo "hahaha = '$VALUE_FETCH_WEATHER_URL'"
|
|
WEATHER=$(curl -sS "$VALUE_FETCH_WEATHER_URL" || echo "${VALUE_WEATHER_ERROR_MESSAGE}")
|
|
|
|
SUNRISE_SUNSET=$(curl -sS "https://wttr.in/${VALUE_WEATHER_LOCATION}${VALUE_SUNSET_SUNRISE_FORMAT}${WEATHER_UNIT}")
|
|
SUNRISE_VALUE=$(echo ${SUNRISE_SUNSET} | cut -c 1-5)
|
|
SUNSET_VALUE=$(echo ${SUNRISE_SUNSET} | cut -c 10-14)
|
|
|
|
if echo "${WEATHER}" | grep -q -P "Unknown\slocation"; then
|
|
WEATHER=${VALUE_WEATHER_ERROR_MESSAGE}
|
|
fi
|
|
|
|
echo "<span font_desc=\"${VALUE_FONT}\" color=\"${VALUE_COLOR}\">${WEATHER} (${SUNRISE_VALUE}-${SUNSET_VALUE})</span>"
|
|
|
|
#echo "x${BUTTON}"
|
|
|
|
if [ ! "x${BUTTON}" == "x" ]; then
|
|
FULL_WEATHER=$(curl -sS "https://wttr.in/${VALUE_WEATHER_LOCATION}?format=%l:+%c+%f+%h+%p+%P+%m+%w+%S+%s" || echo "${VALUE_WEATHER_ERROR_MESSAGE}")
|
|
ACTION=$(notify-send "$FULL_WEATHER")
|
|
/usr/bin/i3-msg -q exec "$ACTION"
|
|
fi
|