103 lines
2.0 KiB
Bash
Executable File
103 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# --- CONFIGURATION ---
|
|
LAT="51.0509" # Replace with your Latitude
|
|
LON="13.7383" # Replace with your Longitude
|
|
UNITS="metric" # Use "metric" for Celsius, "imperial" for Fahrenheit
|
|
TZ="Europe/Berlin"
|
|
# ---------------------
|
|
|
|
if [[ "$UNITS" == "metric" ]]; then
|
|
TEMP_UNIT="celsius"
|
|
LABEL="°C"
|
|
else
|
|
TEMP_UNIT="fahrenheit"
|
|
LABEL="°F"
|
|
fi
|
|
|
|
# Fetch the weather data
|
|
RESPONSE=$(curl -s "https://api.open-meteo.com/v1/forecast?latitude=${LAT}&longitude=${LON}¤t=temperature_2m,weather_code,is_day&timezone=${TZ}")
|
|
|
|
# Check if curl failed to get a response
|
|
if [ -z "$RESPONSE" ]; then
|
|
echo "No connection"
|
|
exit 1
|
|
fi
|
|
|
|
TEMP=$(echo "$RESPONSE" | jq -r '.current.temperature_2m | round')
|
|
CODE=$(echo "$RESPONSE" | jq -r '.current.weather_code')
|
|
IS_DAY=$(echo "$RESPONSE" | jq -r '.current.is_day')
|
|
|
|
case "$CODE" in
|
|
0)
|
|
if [[ "$IS_DAY" == "1" ]]; then
|
|
ICON=" " # nf-weather-day_sunny
|
|
else
|
|
ICON=" " # nf-weather-night_clear
|
|
fi
|
|
DESC="Clear sky"
|
|
;;
|
|
1 | 2)
|
|
if [[ "$IS_DAY" == "1" ]]; then
|
|
ICON=" " # nf-weather-day_cloudy
|
|
else
|
|
ICON=" " # nf-weather-night_alt_cloudy
|
|
fi
|
|
DESC="Partly cloudy"
|
|
;;
|
|
3)
|
|
ICON=" " # nf-weather-cloudy
|
|
DESC="Overcast"
|
|
;;
|
|
45 | 48)
|
|
ICON=" " # nf-weather-fog
|
|
DESC="Fog"
|
|
;;
|
|
51 | 53 | 55)
|
|
ICON=" " # nf-weather-sprinkle
|
|
DESC="Drizzle"
|
|
;;
|
|
56 | 57)
|
|
ICON=" "
|
|
DESC="Freezing drizzle"
|
|
;;
|
|
61 | 63 | 65)
|
|
ICON=" " # nf-weather-rain
|
|
DESC="Rain"
|
|
;;
|
|
66 | 67)
|
|
ICON=" "
|
|
DESC="Freezing rain"
|
|
;;
|
|
71 | 73 | 75 | 77)
|
|
ICON=" " # nf-weather-snow
|
|
DESC="Snow"
|
|
;;
|
|
80 | 81 | 82)
|
|
ICON=" " # nf-weather-showers
|
|
DESC="Rain showers"
|
|
;;
|
|
85 | 86)
|
|
ICON=" "
|
|
DESC="Snow showers"
|
|
;;
|
|
95)
|
|
ICON=" " # nf-weather-thunderstorm
|
|
DESC="Thunderstorm"
|
|
;;
|
|
96 | 99)
|
|
ICON=" "
|
|
DESC="Thunderstorm with hail"
|
|
;;
|
|
esac
|
|
|
|
# Determine unit label
|
|
if [ "$UNITS" = "metric" ]; then
|
|
LABEL="°C"
|
|
else
|
|
LABEL="°F"
|
|
fi
|
|
|
|
# Final JSON output for Waybar
|
|
echo "{\"text\": \"${ICON} ${TEMP}${LABEL}\", \"tooltip\": \"${DESC}\"}"
|