def generate_question_tuple(ctfile, globalErrors=(), func=flag_rst_images): '''yields (ID, concepts, title, question, answer, error1, error2...) tuples with text conversion by func''' tree = parse.process_select(ctfile) questions = get_questions(tree) for q in questions.children: yield question_tuple(q, globalErrors, func)
def export_selected_orct(selectfile, globalErrors=()): 'export JSON for ORCT in a lecture' tree = parse.process_select(selectfile) ctstem = selectfile.split('.')[0] outfile = ctstem + '.json' print 'writing', outfile data = tree.list_repr(textFunc=ctprep.flag_rst_images, postprocDict=parse.PostprocDict) with codecs.open(outfile, 'w', encoding='utf-8') as ofile: json.dump(data, ofile)
def make_slides_and_csv(ctfile, imagepath, title='Concept Tests', globalErrors=()): 'produces CSV for Socraticqs to load, and RST for rst2beamer to convert' tree = parse.process_select(ctfile) questions = get_questions(tree) ctstem = ctfile.split('.')[0] print 'writing', ctstem + '.csv' save_question_csv(questions, ctstem + '.csv', parse.PostprocDict, imagepath, globalErrors=globalErrors) rstout = ctstem + '_slides.rst' print 'writing', rstout with codecs.open(rstout, 'w', encoding='utf-8') as ofile: ofile.write(parse.get_text(tree)) return rstout, tree