diff options
-rwxr-xr-x | daily_planner_generator.py | 104 | ||||
-rw-r--r-- | templates/daily-A6-r.svg | 109 | ||||
-rw-r--r-- | templates/daily-A6-v.svg | 109 |
3 files changed, 322 insertions, 0 deletions
diff --git a/daily_planner_generator.py b/daily_planner_generator.py new file mode 100755 index 0000000..80946d1 --- /dev/null +++ b/daily_planner_generator.py @@ -0,0 +1,104 @@ +#!/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/templates/daily-A6-r.svg b/templates/daily-A6-r.svg new file mode 100644 index 0000000..4e80bff --- /dev/null +++ b/templates/daily-A6-r.svg @@ -0,0 +1,109 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + width="105mm" + height="148mm" + viewBox="0 0 396.85038 559.37009" + version="1.1" + id="svg5" + inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)" + sodipodi:docname="daily-A6-r.svg" + inkscape:export-filename="/home/valhalla/projects/software/pdfscripts/pdfscripts/templates/week_on_two_pages-A6-v.png" + inkscape:export-xdpi="96" + inkscape:export-ydpi="96" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"> + <sodipodi:namedview + id="namedview7" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + inkscape:pagecheckerboard="0" + inkscape:document-units="mm" + showgrid="true" + inkscape:zoom="1.58" + inkscape:cx="276.58228" + inkscape:cy="178.16456" + inkscape:window-width="1161" + inkscape:window-height="830" + inkscape:window-x="117" + inkscape:window-y="56" + inkscape:window-maximized="0" + inkscape:current-layer="layer1" + showguides="true" + inkscape:guide-bbox="true"> + <inkscape:grid + type="xygrid" + id="grid9" + units="mm" + spacingx="3.7795276" + spacingy="3.7795276" /> + <sodipodi:guide + position="0,540.47244" + orientation="0,1" + id="guide1474" + inkscape:label="" + inkscape:locked="false" + inkscape:color="rgb(0,0,255)" /> + <sodipodi:guide + position="0,18.897638" + orientation="0,1" + id="guide1476" + inkscape:label="" + inkscape:locked="false" + inkscape:color="rgb(0,0,255)" /> + <sodipodi:guide + position="37.795276,559.37008" + orientation="-1,0" + id="guide1478" + inkscape:label="" + inkscape:locked="false" + inkscape:color="rgb(0,0,255)" /> + <sodipodi:guide + position="377.95276,559.37008" + orientation="-1,0" + id="guide1480" + inkscape:label="" + inkscape:locked="false" + inkscape:color="rgb(0,0,255)" /> + </sodipodi:namedview> + <defs + id="defs2" /> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <path + style="fill:none;stroke:#7f7f7f;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 37.795278,56.692914 H 377.95276" + id="path1562-3-7" + sodipodi:nodetypes="cc" /> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:24px;line-height:1.25;font-family:sans-serif;text-align:start;text-anchor:start;fill:#404040;fill-opacity:1;stroke:none" + x="36.735123" + y="45.264271" + id="text7108"><tspan + sodipodi:role="line" + id="tspan7106" + x="36.735123" + y="45.264271" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:24px;font-family:Gentium;-inkscape-font-specification:'Gentium, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;text-align:start;text-anchor:start;fill:#404040;fill-opacity:1">{{ day.strftime("%A") }}</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:32px;line-height:1.25;font-family:sans-serif;text-align:end;text-anchor:end;fill:#404040;fill-opacity:1;stroke:none" + x="379.96649" + y="45.230762" + id="text7108-3"><tspan + sodipodi:role="line" + id="tspan7106-5" + x="379.96649" + y="45.230762" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;font-family:Gentium;-inkscape-font-specification:'Gentium, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;text-align:end;text-anchor:end;fill:#404040;fill-opacity:1">{{ day.strftime("%d %B %Y").strip('0') }}</tspan></text> + </g> +</svg> diff --git a/templates/daily-A6-v.svg b/templates/daily-A6-v.svg new file mode 100644 index 0000000..bdc4d56 --- /dev/null +++ b/templates/daily-A6-v.svg @@ -0,0 +1,109 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + width="105mm" + height="148mm" + viewBox="0 0 396.85038 559.37009" + version="1.1" + id="svg5" + inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)" + sodipodi:docname="daily-A6-v.svg" + inkscape:export-filename="/home/valhalla/projects/software/pdfscripts/pdfscripts/templates/week_on_two_pages-A6-v.png" + inkscape:export-xdpi="96" + inkscape:export-ydpi="96" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"> + <sodipodi:namedview + id="namedview7" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + inkscape:pagecheckerboard="0" + inkscape:document-units="mm" + showgrid="true" + inkscape:zoom="2.08" + inkscape:cx="191.82692" + inkscape:cy="87.259615" + inkscape:window-width="1161" + inkscape:window-height="830" + inkscape:window-x="117" + inkscape:window-y="56" + inkscape:window-maximized="0" + inkscape:current-layer="layer1" + showguides="true" + inkscape:guide-bbox="true"> + <inkscape:grid + type="xygrid" + id="grid9" + units="mm" + spacingx="3.7795276" + spacingy="3.7795276" /> + <sodipodi:guide + position="0,540.47244" + orientation="0,1" + id="guide1474" + inkscape:label="" + inkscape:locked="false" + inkscape:color="rgb(0,0,255)" /> + <sodipodi:guide + position="0,18.897638" + orientation="0,1" + id="guide1476" + inkscape:label="" + inkscape:locked="false" + inkscape:color="rgb(0,0,255)" /> + <sodipodi:guide + position="18.897638,559.37008" + orientation="-1,0" + id="guide1478" + inkscape:label="" + inkscape:locked="false" + inkscape:color="rgb(0,0,255)" /> + <sodipodi:guide + position="359.05512,559.37008" + orientation="-1,0" + id="guide1480" + inkscape:label="" + inkscape:locked="false" + inkscape:color="rgb(0,0,255)" /> + </sodipodi:namedview> + <defs + id="defs2" /> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <path + style="fill:none;stroke:#7f7f7f;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m 18.897638,56.692914 340.157482,0" + id="path1562-3-7" + sodipodi:nodetypes="cc" /> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:24px;line-height:1.25;font-family:sans-serif;text-align:end;text-anchor:end;fill:#404040;fill-opacity:1;stroke:none" + x="360.21393" + y="45.264271" + id="text7108"><tspan + sodipodi:role="line" + id="tspan7106" + x="360.21393" + y="45.264271" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:24px;font-family:Gentium;-inkscape-font-specification:'Gentium, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;text-align:end;text-anchor:end;fill:#404040;fill-opacity:1">{{ day.strftime("%A") }}</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:32px;line-height:1.25;font-family:sans-serif;text-align:start;text-anchor:start;fill:#404040;fill-opacity:1;stroke:none" + x="17.015612" + y="45.230762" + id="text7108-3"><tspan + sodipodi:role="line" + id="tspan7106-5" + x="17.015612" + y="45.230762" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;font-family:Gentium;-inkscape-font-specification:'Gentium, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;text-align:start;text-anchor:start;fill:#404040;fill-opacity:1">{{ day.strftime("%d %B %Y").strip('0') }}</tspan></text> + </g> +</svg> |