index sonne und Mond rein und Sat Überflüge
This commit is contained in:
+95
-5
@@ -151,6 +151,24 @@ def action_sun_moon_rise_set(args: list[str]) -> dict:
|
||||
moon_rise = search_event(astronomy.Body.Moon, astronomy.Direction.Rise, observer, start_time, utc_end)
|
||||
moon_set = search_event(astronomy.Body.Moon, astronomy.Direction.Set, observer, start_time, utc_end)
|
||||
|
||||
def search_altitude(direction: astronomy.Direction, altitude_deg: float) -> astronomy.Time | None:
|
||||
limit_days = (utc_end - time_to_datetime(start_time)).total_seconds() / 86400.0
|
||||
result = astronomy.SearchAltitude(astronomy.Body.Sun, observer, direction, start_time, limit_days, altitude_deg)
|
||||
if result is None:
|
||||
return None
|
||||
if time_to_datetime(result) >= utc_end:
|
||||
return None
|
||||
return result
|
||||
|
||||
# Morgens: Sonne steigt auf → Direction.Rise (Höhe wird größer)
|
||||
# Abends: Sonne sinkt ab → Direction.Set (Höhe wird kleiner)
|
||||
astro_dawn = search_altitude(astronomy.Direction.Rise, -18.0)
|
||||
nautical_dawn = search_altitude(astronomy.Direction.Rise, -12.0)
|
||||
civil_dawn = search_altitude(astronomy.Direction.Rise, -6.0)
|
||||
civil_dusk = search_altitude(astronomy.Direction.Set, -6.0)
|
||||
nautical_dusk = search_altitude(astronomy.Direction.Set, -12.0)
|
||||
astro_dusk = search_altitude(astronomy.Direction.Set, -18.0)
|
||||
|
||||
return {
|
||||
"ok": True,
|
||||
"action": "sun_moon_rise_set",
|
||||
@@ -168,14 +186,81 @@ def action_sun_moon_rise_set(args: list[str]) -> dict:
|
||||
"utc_end": utc_end.isoformat().replace("+00:00", "Z"),
|
||||
},
|
||||
"events": {
|
||||
"sunrise": serialize_event("Sonnenaufgang", sun_rise, tz),
|
||||
"sunset": serialize_event("Sonnenuntergang", sun_set, tz),
|
||||
"moonrise": serialize_event("Mondaufgang", moon_rise, tz),
|
||||
"moonset": serialize_event("Monduntergang", moon_set, tz),
|
||||
"astro_dawn": serialize_event("Astronomische Morgendämmerung", astro_dawn, tz),
|
||||
"nautical_dawn": serialize_event("Nautische Morgendämmerung", nautical_dawn, tz),
|
||||
"civil_dawn": serialize_event("Bürgerliche Morgendämmerung", civil_dawn, tz),
|
||||
"sunrise": serialize_event("Sonnenaufgang", sun_rise, tz),
|
||||
"sunset": serialize_event("Sonnenuntergang", sun_set, tz),
|
||||
"civil_dusk": serialize_event("Bürgerliche Abenddämmerung", civil_dusk, tz),
|
||||
"nautical_dusk": serialize_event("Nautische Abenddämmerung", nautical_dusk, tz),
|
||||
"astro_dusk": serialize_event("Astronomische Abenddämmerung", astro_dusk, tz),
|
||||
"moonrise": serialize_event("Mondaufgang", moon_rise, tz),
|
||||
"moonset": serialize_event("Monduntergang", moon_set, tz),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
PLANETS = [
|
||||
("Merkur", astronomy.Body.Mercury),
|
||||
("Venus", astronomy.Body.Venus),
|
||||
("Mars", astronomy.Body.Mars),
|
||||
("Jupiter", astronomy.Body.Jupiter),
|
||||
("Saturn", astronomy.Body.Saturn),
|
||||
("Uranus", astronomy.Body.Uranus),
|
||||
("Neptun", astronomy.Body.Neptune),
|
||||
]
|
||||
|
||||
|
||||
def action_planet_rise_set(args: list[str]) -> dict:
|
||||
if len(args) != 5:
|
||||
fail(
|
||||
"Aktion planet_rise_set erwartet 5 Argumente: latitude longitude elevation date timezone",
|
||||
extra={"argv": args},
|
||||
)
|
||||
|
||||
latitude = parse_float(args[0], "Latitude")
|
||||
longitude = parse_float(args[1], "Longitude")
|
||||
elevation = parse_float(args[2], "Elevation")
|
||||
date_text = args[3]
|
||||
timezone_name = args[4]
|
||||
|
||||
try:
|
||||
datetime.strptime(date_text, "%Y-%m-%d")
|
||||
except ValueError:
|
||||
fail("Datum muss im Format YYYY-MM-DD uebergeben werden.", extra={"date": date_text})
|
||||
|
||||
try:
|
||||
tz = ZoneInfo(timezone_name)
|
||||
except Exception as exc:
|
||||
fail("Zeitzone ist ungueltig.", extra={"details": str(exc)})
|
||||
|
||||
observer = astronomy.Observer(latitude, longitude, elevation)
|
||||
|
||||
local_start = datetime.strptime(date_text, "%Y-%m-%d").replace(tzinfo=tz)
|
||||
local_end = local_start + timedelta(days=1)
|
||||
utc_start = local_start.astimezone(timezone.utc)
|
||||
utc_end = local_end.astimezone(timezone.utc)
|
||||
start_time = dt_to_time(utc_start)
|
||||
|
||||
planets = []
|
||||
for name, body in PLANETS:
|
||||
rise = search_event(body, astronomy.Direction.Rise, observer, start_time, utc_end)
|
||||
set_ = search_event(body, astronomy.Direction.Set, observer, start_time, utc_end)
|
||||
planets.append({
|
||||
"name": name,
|
||||
"rise": serialize_event(name + "aufgang", rise, tz),
|
||||
"set": serialize_event(name + "untergang", set_, tz),
|
||||
})
|
||||
|
||||
return {
|
||||
"ok": True,
|
||||
"action": "planet_rise_set",
|
||||
"date": date_text,
|
||||
"timezone": timezone_name,
|
||||
"planets": planets,
|
||||
}
|
||||
|
||||
|
||||
def classify_visibility(sun_alt_deg: float) -> dict:
|
||||
if sun_alt_deg > -5:
|
||||
return {"key": "day", "label": "Tag"}
|
||||
@@ -1201,7 +1286,12 @@ def main() -> None:
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
return
|
||||
|
||||
fail("Unbekannte Aktion.", extra={"action": action, "available_actions": ["sun_moon_rise_set", "moon_star_occultations", "moon_phase_details", "satellite_passes"]})
|
||||
if action == "planet_rise_set":
|
||||
result = action_planet_rise_set(args)
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
return
|
||||
|
||||
fail("Unbekannte Aktion.", extra={"action": action, "available_actions": ["sun_moon_rise_set", "moon_star_occultations", "moon_phase_details", "satellite_passes", "planet_rise_set"]})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user