summaryrefslogtreecommitdiff
path: root/planner_generator.py
diff options
context:
space:
mode:
Diffstat (limited to 'planner_generator.py')
-rwxr-xr-xplanner_generator.py101
1 files changed, 99 insertions, 2 deletions
diff --git a/planner_generator.py b/planner_generator.py
index 7107d44..66f5890 100755
--- a/planner_generator.py
+++ b/planner_generator.py
@@ -40,11 +40,18 @@ class Generator:
template: Optional[str] = None,
out_file: Optional[str] = None,
build_dir: Optional[str] = "build",
+ latitude: Optional[float] = None,
+ longitude: Optional[float] = None,
+ timezone: Optional[str] = None,
):
self.year = year or (
datetime.date.today() + datetime.timedelta(days=334)
).year
+ self.latitude = latitude
+ self.longitude = longitude
+ self.timezone = timezone
+
self.out_file = out_file or self.default_template + ".pdf"
env = jinja2.Environment()
@@ -143,6 +150,8 @@ class Generator:
class WeeklyGenerator(Generator):
+ """
+ """
default_template = "week_on_two_pages-A6"
def generate_pages(self):
@@ -169,6 +178,8 @@ class WeeklyGenerator(Generator):
class DailyGenerator(Generator):
+ """
+ """
default_template = "daily-A6"
def generate_pages(self):
@@ -213,11 +224,77 @@ class MonthGenerator(Generator):
if day.month == i + 1
])
+ texts = self.get_texts()
+
page = 1
- for month in months:
- self.render_page(page=page, month=month, text=[])
+ for i, month in enumerate(months):
+ self.render_page(page=page, month=month, text=texts[i])
page += 1
+ def get_texts(self):
+ return [[] for i in range(12)]
+
+
+class EphemerismonthGenerator(MonthGenerator):
+ """
+ """
+ default_template = "month-A6"
+
+ def get_texts(self):
+ # we import suntime just here, because it's a third party
+ # library and not used elsewhere
+ try:
+ import astral
+ except ImportError:
+ print("Printing a month planner with ephemeris requires suntime.")
+ 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.Location((
+ "",
+ "",
+ self.latitude,
+ self.longitude,
+ self.timezone,
+ 0
+ ))
+
+ 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)
+ if moon_phase < 7:
+ moon_icon = "●"
+ elif moon_phase < 14:
+ moon_icon = "☽"
+ elif moon_phase < 21:
+ moon_icon = "○"
+ else:
+ moon_icon = "☾"
+ text = ("☼ {sunrise} — {noon} — {sunset} " \
+ + "{moon_icon} {moon_phase}").format(
+ sunrise=sunrise.strftime("%H:%M"),
+ noon=noon.strftime("%H:%M"),
+ sunset=sunset.strftime("%H:%M"),
+ moon_icon=moon_icon,
+ moon_phase=moon_phase,
+ )
+ month.append(text)
+ day += datetime.timedelta(days=1)
+ texts.append(month)
+
+ return texts
+
class Command:
"""
@@ -237,6 +314,23 @@ class Command:
help="Base name of the template (without -[rv].svg)",
)
parser.add_argument(
+ "--latitude",
+ default=None,
+ type=float,
+ help="Latitude for ephemeris calculation",
+ )
+ parser.add_argument(
+ "--longitude",
+ default=None,
+ type=float,
+ help="Longitude for ephemeris calculation",
+ )
+ parser.add_argument(
+ "--timezone",
+ default=None,
+ help="Timezone for ephemeris calculation (e.g. Europe/Rome)",
+ )
+ parser.add_argument(
"command",
)
return parser
@@ -256,6 +350,9 @@ class Command:
generator(
year=self.args.year,
template=self.args.template,
+ latitude=self.args.latitude,
+ longitude=self.args.longitude,
+ timezone=self.args.timezone,
).run()
else:
print("command not supported: {}".format(self.args.command))