diff options
-rwxr-xr-x | daily_planner_generator.py | 104 | ||||
-rwxr-xr-x | planner_generator.py | 29 |
2 files changed, 29 insertions, 104 deletions
diff --git a/daily_planner_generator.py b/daily_planner_generator.py deleted file mode 100755 index 80946d1..0000000 --- a/daily_planner_generator.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import datetime -import locale -import logging -import os -import subprocess -import sys - -import jinja2 - - -locale.setlocale(locale.LC_ALL, '') - - -def main(): - env = jinja2.Environment() - loader = jinja2.FileSystemLoader('templates') - template_verso = loader.load(env, 'daily-A6-v.svg') - template_recto = loader.load(env, 'daily-A6-r.svg') - - destination_fname = "build/daily-A6-{year}-{page:03}.svg" - - os.makedirs("build", exist_ok=True) - - year = 2022 - - template_cover = loader.load(env, 'cover-A6-r.svg') - with open(destination_fname.format( - year=year, - page=0, - ), 'w') as fp: - fp.write(template_cover.render(year=year)) - - day = datetime.date(year, 1, 1) - - page = 1 - while day.year == year: - with open(destination_fname.format( - year=year, - page=page, - ), 'w') as fp: - fp.write(template_verso.render(day=day)) - page += 1 - day += datetime.timedelta(days=1) - - if day.year > year: - break - - with open(destination_fname.format( - year=year, - page=page, - ), 'w') as fp: - fp.write(template_recto.render(day=day)) - page += 1 - day += datetime.timedelta(days=1) - - inkscape_commands = ";\n".join([ - ( - "file-open:build/{svg};" - + " export-type: pdf;" - + " export-filename:build/{pdf};" - + " export-text-to-path;" - + " export-do" - ).format( - svg = s, - pdf = os.path.splitext(s)[0] + ".pdf", - ) - for s in os.listdir("build") - ]) - try: - subprocess.run( - ["inkscape", "--shell" ], - input=inkscape_commands, - text=True, - ) - except FileNotFoundError: - logging.warning("Inkscape is not installed, can't convert to pdf") - logging.warning("Stopping here, you can use the svgs as you like") - sys.exit(1) - - pdf_pages = sorted([ - os.path.join("build", p) - for p in os.listdir("build") - if p.endswith(".pdf") - ]) - # insert an empty page on the second page, to start the year on a - # left page - pdf_pages.insert(1, "1, {}") - try: - subprocess.run([ - "pdfjam", - "--outfile", "daily_planner_A6.pdf", - *pdf_pages - ]) - except FileNotFoundError: - logging.warning("pdfjam is not installed") - logging.warning("you will have to join the pdf pages yourself") - sys.exit(1) - - -if __name__ == '__main__': - main() diff --git a/planner_generator.py b/planner_generator.py index b86ce68..eda562b 100755 --- a/planner_generator.py +++ b/planner_generator.py @@ -168,6 +168,35 @@ class WeeklyGenerator(Generator): page += 1 +class DailyGenerator(Generator): + default_template = "daily-A6" + + def generate_pages(self): + day = datetime.date(self.year, 1, 1) + + # we want to start with a left side page (starting from 0) + page = 2 + while day.year == self.year: + self.render_page(page=page, day=day) + page += 1 + day += datetime.timedelta(days=1) + + if day.year > self.year: + break + + self.render_page(page=page, day=day) + page += 1 + day += datetime.timedelta(days=1) + + def get_pdf_pages(self): + pdf_pages = super().get_pdf_pages() + # insert an empty page on the second page, to start the year on + # a left page + pdf_pages.insert(1, "1, {}") + + return pdf_pages + + class Command: """ Generate a planner |