diff options
Diffstat (limited to 'planner/planner_generator.py')
-rwxr-xr-x | planner/planner_generator.py | 83 |
1 files changed, 80 insertions, 3 deletions
diff --git a/planner/planner_generator.py b/planner/planner_generator.py index 5d9e397..906c0fc 100755 --- a/planner/planner_generator.py +++ b/planner/planner_generator.py @@ -257,9 +257,86 @@ class BiweeklyGenerator(Generator): continue last_monday = week[0] - self.render_page(page=page, week=week) + texts = self.get_texts(week) + + self.render_page(page=page, week=week, text=texts) page += 1 + def get_texts(self, week): + return ["" for i in range(7)] + + +class EphemerisbiweeklyGenerator(BiweeklyGenerator): + """ + """ + default_template = "week_on_one_page-A6" + + def get_texts(self, week): + # we import suntime just here, because it's a third party + # library and not used elsewhere + try: + import astral + import astral.sun + import astral.moon + except ImportError: + print("Printing a planner with ephemeris requires " + "the astral library version 3.x.") + sys.exit(1) + + if not self.latitude or not self.longitude or not self.timezone: + print("Printing ephemeris requires latitude and longitude") + sys.exit(1) + + location = astral.LocationInfo( + "", + "", + self.timezone, + self.latitude, + self.longitude, + ) + local_tz = dateutil.tz.gettz(self.timezone) + + texts = [] + for day in week: + 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: + moon_icon = "☽" + elif moon_phase < 21: + moon_icon = "○" + else: + moon_icon = "☾" + moon_phase = round(moon_phase, 2) + try: + moon_rise = astral.moon.moonrise(location, date=day) + moon_rise = moon_rise.astimezone(local_tz).strftime("%H:%M") + except ValueError: + moon_rise = "" + try: + moon_set = astral.moon.moonset(location, date=day) + moon_set = moon_set.astimezone(local_tz).strftime("%H:%M") + except ValueError: + moon_set= "" + text = ("☼ {sunrise} — {noon} — {sunset} " + + "{moon_icon} ({moon_phase}) " + + "{moon_rise} — {moon_set} " + ).format( + sunrise=sunrise.strftime("%H:%M"), + noon=noon.strftime("%H:%M"), + sunset=sunset.strftime("%H:%M"), + moon_icon=moon_icon, + moon_phase=moon_phase, + moon_rise=moon_rise, + moon_set=moon_set, + ) + texts.append(text) + + return texts class MonthGenerator(Generator): """ @@ -304,8 +381,8 @@ class EphemerismonthGenerator(MonthGenerator): import astral.sun import astral.moon except ImportError: - print("Printing a month planner with ephemeris requires" - "the astral library.") + print("Printing a month planner with ephemeris requires " + "the astral library version 3.x.") sys.exit(1) if not self.latitude or not self.longitude or not self.timezone: |