From 416d3ab277d29d6fb968f51c8a67df301d014fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Sat, 20 Nov 2021 09:40:32 +0100 Subject: [PATCH] feat(i3status-rust): show moon fullness percentage --- lib/i3status-rust.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/i3status-rust.nix b/lib/i3status-rust.nix index 0fe0b58..82bbfe5 100644 --- a/lib/i3status-rust.nix +++ b/lib/i3status-rust.nix @@ -105,6 +105,7 @@ in { import astral import astral.moon import astral.sun + import math moon_phases = { 0: "🌑", @@ -120,10 +121,12 @@ in { current_phase = astral.moon.phase() closest_phase = min(moon_phases.keys(), key=lambda x: abs(current_phase - x)) + moon_percentage = round(100 * math.sin(current_phase / 28 * math.pi), 1) + city = astral.LocationInfo("Berlin", "Germany", "${spacetime.time.timeZone}", ${toString spacetime.location.latitude}, ${toString spacetime.location.longitude}) sun = astral.sun.sun(city.observer, date=astral.today(), tzinfo=city.timezone) - print("🌅 {} 🌇 {} {}".format(sun["sunrise"].strftime("%R"), sun["sunset"].strftime("%R"), moon_phases[closest_phase])) + print("🌅 {} 🌇 {} {} {}%".format(sun["sunrise"].strftime("%R"), sun["sunset"].strftime("%R"), moon_phases[closest_phase], moon_percentage)) ''; } {