speedwm-personal/modules/module_weather

94 lines
2.1 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# weather module for status/stellar
# load config
2022-10-27 17:51:19 +02:00
. $HOME/.config/speedwm/statusrc
2022-10-25 19:23:36 +02:00
BINDIR="$(dirname $(command -v speedwm_status))/"
# argument 1
ARG1="$1"
# clicking
CLICK() {
# values
WEATHER_TERM="speedwm-core -curl-weather"
ICON="$ITEM5_ICON"
BUTTON="$(cat /tmp/speedwm-button)"
case "$TERMINAL" in
"") TERMINAL=st
esac
case "$BUTTON" in
"3") $TERMINAL speedwm-core -curl-weather ; exit ;;
esac
# check if a forecast exists
# status script should create this
if [ -e "/tmp/wstatus" ]; then
FORECAST="$(cat /tmp/wstatus)"
else
echo "FATAL: No weather status available!"
2022-10-25 21:22:05 +02:00
exit
fi
2022-10-25 21:22:05 +02:00
grep -q "Unknown location" /tmp/wstatus && exit
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
# send the notification
SEND_NOTIF() {
FULL_WEATHER="${ICON}${ICONSPACING}$FORECAST"
notify-send "$FULL_WEATHER"
echo "Notification sent successfully!"
echo "INFO: $FULL_WEATHER"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1
}
# information itself
PRINT() {
if [ "$ENABLE_ITEM5" = "true" ]; then
if [ -e "${BINDIR}curl" ]; then
if [ -e "/tmp/itest" ]; then
if [ -e "/tmp/wstatus" ]; then
2022-10-25 21:22:05 +02:00
grep -q "Unknown location" /tmp/wstatus && exit
2022-11-01 23:20:11 +01:00
grep -q "<html>" /tmp/wstatus && exit
echo "$ITEM5_SEPARATOR $ITEM5_ICON $(cat /tmp/wstatus)"
else
echo "$(curl -s wttr.in/?format="%C"), $(curl -s wttr.in/?format=3 | sed 's/.* //; s/.*\(.....\)/\1/')" > /tmp/wstatus
echo "$ITEM5_SEPARATOR $ITEM5_ICON $(cat /tmp/wstatus)"
fi
[ -z "$ITEM5_APPEND" ] || echo "$ITEM5_APPEND"
else
curl -so /tmp/itest wttr.in && hasinternet=true
if [ "$hasinternet" != "true" ]; then
rm -f /tmp/itest
rm -f /tmp/wstatus
itemcmd5=""
fi
fi
fi
fi
}
# argument 1
case "$ARG1" in
"") CLICK ;;
"--print-file") PRINT > /tmp/module_weather ;;
"--print") PRINT ;;
"--click") CLICK ;;
esac