Improve tooling

This commit is contained in:
Pascal Le Merrer 2026-02-28 11:23:55 +01:00
parent 458352da97
commit 3165d050a1
3 changed files with 24 additions and 16 deletions

View file

@ -1,6 +1,8 @@
#!python
# Copies the given input file, removing the parts specific to the Web,
# so it can be converted to an email
from datetime import date
from docutils.parsers.rst.directives.misc import Date
import subprocess
import argparse
@ -11,13 +13,10 @@ MAIL_GENERATOR = "/opt/homebrew/bin/mdtosendy"
parser = argparse.ArgumentParser()
parser.add_argument("source")
parser.add_argument("-n", "--number", required=True, type=int, help="Newsletter number")
args = parser.parse_args()
root = Path.cwd()
print(f"Root: {root}")
source = Path(root / args.source)
source = Path(f"./content/newsletter/craft-letter-{args.number}.md")
if not source.is_file():
print(f"ERROR: file not found {source}")
@ -34,4 +33,12 @@ destination = Path.cwd() / "mail" / source.name
print(f"Writing {destination}")
destination.write_text(output)
subprocess.run([MAIL_GENERATOR, "--preview", str(destination)])
subprocess.run([MAIL_GENERATOR, str(destination)])
generated_mail = Path("mail") / f"craft-letter-{args.number}.html"
today = date.today()
mail_content = generated_mail.read_text()
mail_content = mail_content.replace("{{YEAR}}", str(today.year))
generated_mail.write_text(mail_content)
subprocess.run(["open", str(generated_mail)])