"""Split 6 per-app instruction bodies into 12 segment files (4w / 8w).""" import re from pathlib import Path ROOT = Path(__file__).resolve().parents[1] INST = ROOT / "_templates" / "instructions" SPLITS = [ ("time_ce_body.html", "time_ce_48_4w.html", "time_ce_48_8w.html"), ("time_ce_84_body.html", "time_ce_84_4w.html", "time_ce_84_8w.html"), ("time_lot_1_body.html", "time_Lot_1_48_4w.html", "time_Lot_1_48_8w.html"), ("time_lot_1_84_body.html", "time_Lot_1_84_4w.html", "time_Lot_1_84_8w.html"), ("time_lot_2_body.html", "time_Lot_2_48_4w.html", "time_Lot_2_48_8w.html"), ("time_lot_2_84_body.html", "time_Lot_2_84_4w.html", "time_Lot_2_84_8w.html"), ] CLOSING = "\n{% include 'instructions/instructions_closing.html' %}\n" def split_file(src_name: str, out_4w: str, out_8w: str) -> None: text = INST.joinpath(src_name).read_text(encoding="utf-8") m4 = re.search( r"\{% if instruction_segment == '4w' %\}\s*(.*?)\s*\{% elif instruction_segment == '8w' %\}", text, re.DOTALL, ) m8 = re.search( r"\{% elif instruction_segment == '8w' %\}\s*(.*?)\s*\{% endif %\}", text, re.DOTALL, ) if not m4 or not m8: raise ValueError(f"Could not split segments in {src_name}") INST.joinpath(out_4w).write_text(m4.group(1).strip() + CLOSING, encoding="utf-8") INST.joinpath(out_8w).write_text(m8.group(1).strip() + CLOSING, encoding="utf-8") print(f" {out_4w}, {out_8w}") def main() -> None: print("Writing 12 instruction body files:") for row in SPLITS: split_file(*row) print("Done.") if __name__ == "__main__": main()