Generalize weather module

This commit is contained in:
Jimbo 2024-09-13 02:03:02 -04:00
parent c2edd633cf
commit 6819e05bb9

View file

@ -203,13 +203,10 @@
}; };
weatherModule = { weatherModule = {
exec = pkgs.writeScript "weatherScript" '' exec = pkgs.writeScript "weatherScript" ''
# Define variables
CITY="Maple"
API_KEY="18be8db3528f08c33ed9f95698335ea7"
# Fetch weather data # Fetch weather data
weather_data=$(curl -s "http://api.openweathermap.org/data/2.5/weather?q=$CITY&appid=$API_KEY") weather=$(fastfetch -c all -s weather -l none)
weather_condition=$(echo $weather_data | jq -r '.weather[0].main') weather_temp=$(echo $weather | awk '{print $2}' | sed 's/^\+//')
weather_condition=$(echo $weather | awk '{print $4}')
# Map weather conditions to emojis # Map weather conditions to emojis
case "$weather_condition" in case "$weather_condition" in
@ -223,17 +220,11 @@
*) emoji="🌍";; # Default emoji for unknown *) emoji="🌍";; # Default emoji for unknown
esac esac
# Extract and format temperature in Celsius
temperature_kelvin=$(echo $weather_data | jq -r '.main.temp')
temperature_celsius=$(echo "$temperature_kelvin - 273.15" | bc)
formatted_temperature=$(printf "%.0f" $temperature_celsius)
# Display weather emoji and temperature # Display weather emoji and temperature
echo {\"text\":\"$emoji $formatted_temperature°C\",\"tooltip\":\"Weather in $CITY: $weather_condition\"} echo {\"text\":\"$emoji $weather_temp\",\"tooltip\":\"Condition: $weather_condition\"}
''; '';
format = "<span font_size='11pt'>{}</span>"; format = "<span font_size='11pt'>{}</span>";
return-type = "json"; return-type = "json";
on-click = "xdg-open https://openweathermap.org/city/6173577 | notify-send 'Opening weather'";
interval = 150; interval = 150;
}; };