From f48a7a84430718702a587e8544b818557c33ab86 Mon Sep 17 00:00:00 2001 From: gtitov Date: Tue, 21 Jun 2022 13:26:52 +0300 Subject: [PATCH] some docs --- main.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 72981c2..7680025 100644 --- a/main.py +++ b/main.py @@ -31,6 +31,7 @@ with open("students.json", "r", encoding="UTF-8") as f: content = json.load(f) students = content["students"] +# create folders if they don't exist Path("answers").mkdir(parents=True, exist_ok=True) Path("results").mkdir(parents=True, exist_ok=True) @@ -51,7 +52,17 @@ def show_students(): @app.get("/give_quiz") def give_quiz(student_id, student: str): - questions_for_student = random.sample(quiz_questions, len(quiz_questions))[:1] # random order and only first n questions + """Give json-like quiz + + Args: + student_id (int): indentificator of a student + student (str): student name + + Returns: + obj: json-like quiz + """ + quiz_length = 1 + questions_for_student = random.sample(quiz_questions, len(quiz_questions))[:quiz_length] # random order and only first n questions return { "version": 1, "student_id": student_id, @@ -62,6 +73,14 @@ def give_quiz(student_id, student: str): @app.get("/get_student_answers") def get_answers(student_answers: str): + """Save answers as-is and checked answers + + Args: + student_answers (str): json-like string with student's answers + + Returns: + str: student name + """ json_answers = json.loads(student_answers) print(json_answers) path_to_answers = f'answers/{json_answers["student"]}_{json_answers["attempt"]}.json'