diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2023-11-22 18:07:06 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2023-11-22 18:07:06 +0100 |
commit | 507f0c2e2d5119d0c133b338ee186c2b7c806d93 (patch) | |
tree | e8a05fcada38742af3303e16d07888550d797bcb /planner | |
parent | 4cc35aaab4daf2d2d74ec79057c368cf895d7a1c (diff) |
Fix ephemerid calculations with the new astral
Diffstat (limited to 'planner')
-rwxr-xr-x | planner/planner_generator.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/planner/planner_generator.py b/planner/planner_generator.py index 570c769..d748fff 100755 --- a/planner/planner_generator.py +++ b/planner/planner_generator.py @@ -12,6 +12,8 @@ import sys from typing import Optional +import dateutil.tz + try: from lesana.command import _get_first_docstring_line # type: ignore except ImportError: @@ -274,6 +276,8 @@ class EphemerismonthGenerator(MonthGenerator): # library and not used elsewhere try: import astral + import astral.sun + import astral.moon except ImportError: print("Printing a month planner with ephemeris requires" "the astral library.") @@ -283,26 +287,28 @@ class EphemerismonthGenerator(MonthGenerator): print("Printing ephemeris requires latitude and longitude") sys.exit(1) - location = astral.Location(( + location = astral.LocationInfo( "", "", + self.timezone, self.latitude, self.longitude, - self.timezone, - 0 - )) + ) + local_tz = dateutil.tz.gettz(self.timezone) day = datetime.date(self.year, 1, 1) + texts = [] while day.year == self.year: month = [] this_month = day.month while day.month == this_month: - sunrise = location.sunrise(day) - noon = location.solar_noon(day) - sunset = location.sunset(day) - moon_phase = location.moon_phase(day) + sun = astral.sun.sun(location.observer, date=day) + sunrise = sun["sunrise"].astimezone(local_tz) + noon = sun["noon"].astimezone(local_tz) + sunset = sun["sunset"].astimezone(local_tz) + moon_phase = astral.moon.phase(day) if moon_phase < 7: moon_icon = "●" elif moon_phase < 14: @@ -311,6 +317,7 @@ class EphemerismonthGenerator(MonthGenerator): moon_icon = "○" else: moon_icon = "☾" + moon_phase = round(moon_phase) text = ("☼ {sunrise} — {noon} — {sunset} " + "{moon_icon} {moon_phase}").format( sunrise=sunrise.strftime("%H:%M"), |