Generalize weather module
This commit is contained in:
parent
c2edd633cf
commit
6819e05bb9
|
@ -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 = "<span font_size='11pt'>{}</span>";
|
||||
return-type = "json";
|
||||
on-click = "xdg-open https://openweathermap.org/city/6173577 | notify-send 'Opening weather'";
|
||||
interval = 150;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue