ccpq/poc_hugo.py

65 lines
1.6 KiB
Python

#!/usr/bin/python3
import pathlib
import time
import os
import csv
import random
from collections import Counter
from rich.console import Console
from rich.markdown import Markdown
# 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
# 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"
dictionary = _create_dictionary()
questions_id = _count_questions(dictionary)
random.shuffle(dictionary)
for question in dictionary:
_print_question(question)
result = _test_question(question)
#_get_question(dictionary, questions_id)