From 6819e05bb9ee5aeea1d93328be8b6782e999de88 Mon Sep 17 00:00:00 2001 From: Jimbo Date: Fri, 13 Sep 2024 02:03:02 -0400 Subject: [PATCH] Generalize weather module --- home-manager/sway/waybar.nix | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/home-manager/sway/waybar.nix b/home-manager/sway/waybar.nix index f9436a3..f936440 100644 --- a/home-manager/sway/waybar.nix +++ b/home-manager/sway/waybar.nix @@ -203,13 +203,10 @@ }; weatherModule = { exec = pkgs.writeScript "weatherScript" '' - # Define variables - CITY="Maple" - API_KEY="18be8db3528f08c33ed9f95698335ea7" - # Fetch weather data - weather_data=$(curl -s "http://api.openweathermap.org/data/2.5/weather?q=$CITY&appid=$API_KEY") - weather_condition=$(echo $weather_data | jq -r '.weather[0].main') + weather=$(fastfetch -c all -s weather -l none) + weather_temp=$(echo $weather | awk '{print $2}' | sed 's/^\+//') + weather_condition=$(echo $weather | awk '{print $4}') # Map weather conditions to emojis case "$weather_condition" in @@ -223,17 +220,11 @@ *) emoji="🌍";; # Default emoji for unknown 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 - echo {\"text\":\"$emoji $formatted_temperature°C\",\"tooltip\":\"Weather in $CITY: $weather_condition\"} + echo {\"text\":\"$emoji $weather_temp\",\"tooltip\":\"Condition: $weather_condition\"} ''; format = "{}"; return-type = "json"; - on-click = "xdg-open https://openweathermap.org/city/6173577 | notify-send 'Opening weather'"; interval = 150; };