import json, sys sys.path.insert(0, "/Users/drjones/pest-nocturne") from wa_exam_data import WAEXAM p = "/Users/drjones/pest-nocturne/index.html" s = open(p).read() # 1. Add WA Prep tab to VIEWS old_views = 'const VIEWS=[["home","Suite"],["field","Field Guide"],["keys","Keys"],["house","22 Points"],["cards","Flashcards"],["exam","Exam"],["gloss","Glossary"],["wa","WA Cert"]];' new_views = 'const VIEWS=[["home","Suite"],["field","Field Guide"],["keys","Keys"],["house","22 Points"],["cards","Flashcards"],["exam","Exam"],["gloss","Glossary"],["wa","WA Cert"],["waprep","WA Prep"]];' assert old_views in s, "VIEWS not found" s = s.replace(old_views, new_views) # 2. Add section old_sec = '
' new_sec = old_sec + '\n
' assert old_sec in s, "v-wa section not found" s = s.replace(old_sec, new_sec) # 3. Build the WA Prep view + quiz (self-contained) wa_data_json = json.dumps(WAEXAM) # [{cat,q,a:[...],c,x},...] RENDER = r''' '''.replace('__WADATA__', wa_data_json) s = s.rstrip() + '\n' + RENDER + '\n' open(p, "w").write(s) print(f"injected WA Prep view with {len(WAEXAM)} questions; size {len(s)}")