import json, sys, re p = "/Users/drjones/pest-nocturne/index.html" s = open(p).read() # build merged question bank sys.path.insert(0, "/Users/drjones/pest-nocturne") import wa_exam_data2 as d2 WA = [] for cat in ["Core", "Structural", "Ornamental & Turf", "Agricultural"]: for q, a, c, x in d2.ALL[cat]: WA.append({"cat": cat, "q": q, "a": a, "c": c, "x": x}) # add EM019 manual questions EM = json.load(open("/tmp/em019_exam.json")) ALLQ = WA + EM print(f"WA original: {len(WA)}, EM019 manual: {len(EM)}, total: {len(ALLQ)}") # remove the old WA Prep block (from its '''.replace('__WADATA__', data_json) s = s.rstrip() + '\n' + RENDER + '\n' open(p, "w").write(s) print(f"rebuilt WA Prep with {len(ALLQ)} questions + mock exam; size {len(s)}")