|
|
|
|
|
import csv |
|
|
|
writer = csv.writer(open('./source3.csv', 'w')) |
|
|
|
content = open('../genetic-counseling-multiple-choice-3.txt', 'r').read().split('ANSWER') |
|
|
|
source = 'https://quizlet.com/476301059/genetic-counseling-boards-review-questions-flash-cards/' |
|
author = 'kelsie_cain' |
|
|
|
writer.writerow(['source', 'author', 'question', 'optionA', 'optionB', 'optionC', 'optionD', 'letter_answer']) |
|
|
|
for idx, q in enumerate(content): |
|
if idx == len(content) - 1: |
|
break |
|
q_and_a = q[q.index('\n') + 1:].strip() |
|
question = q_and_a[:q_and_a.index('A.')].strip() |
|
option_A = q_and_a[q_and_a.index('\nA.') + 3 : q_and_a.index('\nB.')].strip() |
|
option_B = q_and_a[q_and_a.index('\nB.') + 3 : q_and_a.index('\nC.')].strip() |
|
option_C = q_and_a[q_and_a.index('\nC.') + 3 : q_and_a.index('\nD.')].strip() |
|
option_D = q_and_a[q_and_a.index('\nD.') + 3 : ].strip() |
|
|
|
letter_answer = content[idx + 1].split('\n')[0].strip() |
|
writer.writerow([source, author, question, option_A, option_B, option_C, option_D, letter_answer]) |
|
|