quiz-the-word/scripts/file_parsing.py

27 lines
928 B
Python
Raw Permalink Normal View History

2023-11-27 19:25:33 -08:00
from __future__ import annotations
2021-03-18 20:08:19 -07:00
import pathlib
def parse_multiple_choice_questions(question_file: pathlib.Path):
file_data = question_file.read_text("utf-8").split("\n")
questions = []
for line in file_data:
question_data = line.split("~")
if len(question_data) == 4:
correct_answer_index = int(question_data[0])-1
question = question_data[1]
answer_list = question_data[2].split("//")
2023-11-27 19:25:33 -08:00
bible_verse = question_data[3] if question_data[3].lower(
) != "none" else None
2021-03-18 20:08:19 -07:00
correct_answer = answer_list.pop(correct_answer_index)
questions.append({
"question": question,
"answer": correct_answer,
"addresses": bible_verse,
"difficulty": None,
"hint": None,
"wrong_answers": answer_list,
})
return questions