Files
dotfiles/config/waybar/scripts/weather.sh
T
2026-09-23 00:44:36 +05:00

27 lines
871 B
Bash
Executable File

#!/usr/bin/env bash
# Get weather data from wttr.in with geolocation from ipinfo.io
# You can override with WEATHER_LOCATION environment variable
LOCATION="${WEATHER_LOCATION:-}"
# If no location is set, fetch it from ipinfo.io
if [ -z "$LOCATION" ]; then
LOCATION=$(curl -s "https://ipinfo.io/" | jq -r '.city // empty')
fi
# Fetch weather using wttr.in
if [ -n "$LOCATION" ]; then
WEATHER_DATA=$(curl -s "wttr.in/$LOCATION?format=%c+%t")
TOOLTIP=$(curl -s "wttr.in/$LOCATION?format=%l:+%c+%t+%w+%p+%h")
else
WEATHER_DATA=$(curl -s "wttr.in/?format=%c+%t")
TOOLTIP=$(curl -s "wttr.in/?format=%l:+%c+%t+%w+%p+%h")
fi
# Check if curl was successful
if [ $? -eq 0 ] && [ -n "$WEATHER_DATA" ]; then
echo "{\"text\":\"$WEATHER_DATA\", \"tooltip\":\"$TOOLTIP\"}"
else
echo "{\"text\":\"🌡 N/A\", \"tooltip\":\"Weather data unavailable\"}"
fi