From 4e18ce69111ae574bd8bd938303c8782c83f8791 Mon Sep 17 00:00:00 2001 From: Ezekiel Date: Fri, 28 May 2021 16:01:01 +0200 Subject: [PATCH] Continued exec --- poc_hugo.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/poc_hugo.py b/poc_hugo.py index 4dc2cc3..d89302c 100644 --- a/poc_hugo.py +++ b/poc_hugo.py @@ -9,18 +9,57 @@ from collections import Counter from rich.console import Console from rich.markdown import Markdown -def _create_dictionnary(): + +# Open the CSV file and create a dictionary with all the questions +def _create_dictionary(): with open(path) as file: reader = csv.DictReader(file) data = list(reader) + return data - question = random.choice(data) - return question + +# Count the number of questions and generate a list of IDs +def _count_questions(dictionary): + questions_id = [0] + questions_counter = 0 + for questions in dictionary: + questions_counter += 1 + questions_id.append(questions_counter) + questions_id.pop() + return questions_id + + +def _get_question(dictionary, questions_id): + questions_numbers = questions_id + + print(questions_numbers) + + +def _print_question(question_asked): + os.system("clear") + c = Console() + actual_question = "# {}".format(question_asked["QUESTION"]) + actual_question = Markdown(actual_question) + c.print(actual_question) + answers = [] + for i in question_asked.keys(): + if i.isnumeric(): + answers.append(question_asked[i]) + answer = "" + for i in answers: + answer += "1. {} \n".format(i) + answer = Markdown(answer) + c.print(answer) + +def _test_question(question_asked) if __name__ == "__main__": path = "./data/list_book1.csv" - _create_dictionnary() - print(get_random_question()) + dictionary = _create_dictionary() + questions_id = _count_questions(dictionary) + random.shuffle(dictionary) + for question in dictionary: + _print_question(question) + result = _test_question(question) - - print() \ No newline at end of file + #_get_question(dictionary, questions_id) \ No newline at end of file