From 90befc0953ee9074d9a73b6d9937a478b6c25503 Mon Sep 17 00:00:00 2001 From: Abdellah Date: Fri, 11 Jun 2021 09:15:25 +0200 Subject: [PATCH] add poc --- poc_abdellah.py | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 poc_abdellah.py diff --git a/poc_abdellah.py b/poc_abdellah.py new file mode 100644 index 0000000..71806b5 --- /dev/null +++ b/poc_abdellah.py @@ -0,0 +1,91 @@ +#!/usr/bin/python3 + +import pathlib +import csv +import random +import os +from rich.console import Console +from rich.markdown import Markdown + + +def loading_file(file_path): + # loading file to working with + + diction_reader = csv.DictReader(open(file_path, "r")) + data = [] + for e in diction_reader: + data.append(e) + return data + + +def choice_question(data): + choice = random.choice(data) + return choice + + +def show_questions(choice): + os.system("clear") + c = Console() + quest = "# {}".format(choice["QUESTION"]) + quest = Markdown(quest) + c.print(quest) + + +def show_answers(choice): + os.system("clear") + c = Console() + answer = [] + for i in choice.keys(): + if i.isnumeric(): + answer.append(choice[i]) + answers = "" + for i in answer: + if len(i) > 0: + answers += "1. {} \n".format(i) + answers = Markdown(answers) + c.print() + c.print(answers) + + +def prompt_answer(choice): + reply_answ = input("What is your answer ? ") + if reply_answ in choice["ANSWER"]: + return True + else: + return False + + +def print_explication(choice): + c = Console() + explication = "# {}".format(choice["EXPLICATION"]) + explication = Markdown(explication) + c.print(explication) + + +def print_success(choice): + c = Console() + if choice: + mess1 = "## Good Answer!" + else: + mess1 = "## Ho no ... ! that's not the right answer..." + mess = Markdown(mess1) + c.print(mess) + + +def print_stats(): + pass + + +if __name__ == "__main__": + file_path = pathlib.Path('./data/list_book1.csv') + data = loading_file(file_path) + try: + while True: + result = choice_question(data) + show_questions(result) + show_answers(result) + result1 = prompt_answer(result) + print_success(result1) + print_explication(result) + except KeyboardInterrupt: + print("Ciao Ciao")