Moonyear verbessert für export

This commit is contained in:
Eskimue
2026-04-22 13:20:31 +02:00
parent 5141751d0b
commit ce69bd90c5
3 changed files with 607 additions and 297 deletions
+45
View File
@@ -2834,6 +2834,46 @@ def serialize_time_only(time_value: astronomy.Time, tz: ZoneInfo) -> dict:
}
def action_lunar_eclipses_for_year(args: list[str]) -> dict:
if len(args) != 2:
fail("Aktion lunar_eclipses_for_year erwartet 2 Argumente: year timezone", extra={"argv": args})
try:
year = int(args[0])
except ValueError as exc:
fail("Jahr ist ungueltig.", extra={"details": str(exc)})
timezone_name = args[1]
try:
tz = ZoneInfo(timezone_name)
except Exception as exc:
fail("Zeitzone ist ungueltig.", extra={"details": str(exc)})
year_start = datetime(year, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
year_end = datetime(year + 1, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
scan_start = dt_to_time(year_start - timedelta(days=20))
eclipses = []
lunar = astronomy.SearchLunarEclipse(scan_start)
while True:
peak_utc = time_to_datetime(lunar.peak)
if peak_utc >= year_end:
break
if peak_utc >= year_start:
local_peak = peak_utc.astimezone(tz)
eclipses.append({
"kind": lunar.kind.name.lower(),
"month": local_peak.month,
"day": local_peak.day,
"local_date": local_peak.strftime("%d.%m.%Y"),
"local_time": local_peak.strftime("%H:%M"),
"utc_iso": peak_utc.isoformat().replace("+00:00", "Z"),
})
lunar = astronomy.NextLunarEclipse(lunar.peak)
return {"ok": True, "action": "lunar_eclipses_for_year", "year": year, "eclipses": eclipses}
def action_eclipses_for_month(args: list[str]) -> dict:
if len(args) != 6:
fail(
@@ -5057,6 +5097,11 @@ def main() -> None:
print(json.dumps(result, ensure_ascii=True))
return
if action == "lunar_eclipses_for_year":
result = action_lunar_eclipses_for_year(args)
print(json.dumps(result, ensure_ascii=True))
return
fail("Unbekannte Aktion.", extra={"action": action, "available_actions": ["sun_moon_rise_set", "solar_longitude_to_datetime", "current_solar_longitude", "astronomical_conversions", "comet_brightnesses", "favorite_comet_events_for_month", "moon_star_occultations", "moon_phase_details", "satellite_passes", "planet_rise_set", "planet_visibility_chart", "month_sky_context", "moon_phases_for_month", "golden_handle_for_month", "season_changes_for_month", "time_changes_for_month", "moon_planet_approaches", "moon_deep_sky_approaches_for_month", "planet_bright_star_approaches_for_month", "planet_conjunctions_for_month", "eclipses_for_month", "moon_apsides_for_month", "sun_apsides_for_month", "inner_planet_elongations_for_month", "venus_peak_magnitude_for_month", "outer_planet_events_for_month", "outer_planet_stations_for_month", "jupiter_moons_one_side_for_month", "mercury_good_visibility_for_month", "planet_parades_for_month", "planet_constellation_changes_for_month", "moon_star_occultations_for_month"]})