diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2021-12-28 16:16:59 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2021-12-28 16:16:59 +0100 |
commit | 81a6987e04106e8168b55cd84fbe6a7cd8a9d912 (patch) | |
tree | a1769bed4da630f39c823af8d61a6d26d8146058 /weekly_planner_generator.py | |
parent | bfaa3d29bbc6e485da1923afb1cebfcf9f0a1477 (diff) |
Converted weekly planner generator into a proper command
Diffstat (limited to 'weekly_planner_generator.py')
-rwxr-xr-x | weekly_planner_generator.py | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/weekly_planner_generator.py b/weekly_planner_generator.py deleted file mode 100755 index 4ba491e..0000000 --- a/weekly_planner_generator.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import calendar -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, 'week_on_two_pages-A6-v.svg') - template_recto = loader.load(env, 'week_on_two_pages-A6-r.svg') - - os.makedirs("build", exist_ok=True) - - year = 2022 - - template_cover = loader.load(env, 'cover-A6-r.svg') - with open("build/week_on_two_pages-A6-{year}-{page:03}.svg".format( - year=year, - page=0, - ), 'w') as fp: - fp.write(template_cover.render(year=year)) - - cal = calendar.Calendar() - weeks = sum([r[0] for r in cal.yeardatescalendar(2022, width=1)], []) - - last_monday = None - page = 1 - for week in weeks: - # yeardatescalendar will have the same week twice at the margin - # of a month, but we want to skip one of those - if week[0] == last_monday: - continue - last_monday = week[0] - - with open("build/week_on_two_pages-A6-{year}-{page:03}.svg".format( - year=year, - page=page, - ), 'w') as fp: - fp.write(template_verso.render(week=week)) - page += 1 - - with open("build/week_on_two_pages-A6-{year}-{page:03}.svg".format( - year=year, - page=page, - ), 'w') as fp: - fp.write(template_recto.render(week=week)) - page += 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") - ]) - try: - subprocess.run([ - "pdfjam", - "--outfile", "weekly_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() |