2022-10-08 02:31:35 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# weather module for status/stellar
|
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# load config
|
|
|
|
. $HOME/.config/speedwm-de/status/config
|
2022-10-25 19:23:36 +02:00
|
|
|
BINDIR="$(dirname $(command -v speedwm_status))/"
|
2022-10-08 12:47:57 +02:00
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# argument 1
|
|
|
|
ARG1="$1"
|
2022-10-08 12:47:57 +02:00
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# 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!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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."
|
|
|
|
|
2022-10-08 02:31:35 +02:00
|
|
|
exit 1
|
2022-10-21 13:35:02 +02:00
|
|
|
}
|
2022-10-08 02:31:35 +02:00
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# information itself
|
|
|
|
PRINT() {
|
|
|
|
if [ "$ENABLE_ITEM5" = "true" ]; then
|
|
|
|
if [ -e "${BINDIR}curl" ]; then
|
|
|
|
if [ -e "/tmp/itest" ]; then
|
|
|
|
if [ -e "/tmp/wstatus" ]; then
|
|
|
|
grep -q "<html>" /tmp/wstatus || echo "$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 "$SEPARATOR $ITEM5_ICON $(cat /tmp/wstatus)"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
curl -so /tmp/itest wttr.in && hasinternet=true
|
2022-10-08 02:31:35 +02:00
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
if [ "$hasinternet" != "true" ]; then
|
|
|
|
rm -f /tmp/itest
|
|
|
|
rm -f /tmp/wstatus
|
|
|
|
itemcmd5=""
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2022-10-08 02:31:35 +02:00
|
|
|
}
|
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# argument 1
|
|
|
|
case "$ARG1" in
|
|
|
|
"") CLICK ;;
|
|
|
|
"--print") PRINT > /tmp/module_weather ;;
|
|
|
|
"--click") CLICK ;;
|
|
|
|
esac
|