From c3cdbba14b27c2819d6ff3fcb65669e7867fb0dd Mon Sep 17 00:00:00 2001 From: gtitov Date: Wed, 26 Oct 2022 15:10:27 +0300 Subject: [PATCH] initial files to variables --- main.py | 20 +++----------------- settings.py | 4 +++- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/main.py b/main.py index 17d022a..011f29f 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ import random from pathlib import Path from datetime import datetime -from settings import WAVE, END_TEST_PASSWORD, QUIZ_LENGTH +from settings import WAVE, END_TEST_PASSWORD, QUIZ_LENGTH, QUESTIONS_FILE, STUDENTS_FILE app = FastAPI() @@ -22,22 +22,8 @@ app.add_middleware( # CORS allow_headers=["*"], ) - -# student_answers_example = { -# "version": 1, -# "student": "asd", -# "wave": 0, -# "questions": [ -# { -# "id": 4, -# "question": "Сколько винтов у теодолита?", -# "student_answer": 100 -# } -# ] -# } - # open files once and use variables after -with open("questions.json", "r", encoding="UTF-8") as f: +with open(QUESTIONS_FILE, "r", encoding="UTF-8") as f: content = json.load(f) all_questions = content["questions"] topics_questions = all_questions # don't use topics for now. see next to lines to use topics @@ -46,7 +32,7 @@ with open("questions.json", "r", encoding="UTF-8") as f: remove_keys = ["author", "answer", "topic"] quiz_questions = [{key: value for key, value in q.items() if key not in remove_keys} for q in topics_questions] -with open("students.json", "r", encoding="UTF-8") as f: +with open(STUDENTS_FILE, "r", encoding="UTF-8") as f: content = json.load(f) students = content["students"] diff --git a/settings.py b/settings.py index 5c501e1..7dbc377 100644 --- a/settings.py +++ b/settings.py @@ -1,3 +1,5 @@ WAVE = 1 END_TEST_PASSWORD = "qwe" -QUIZ_LENGTH = 4 \ No newline at end of file +QUIZ_LENGTH = 4 +QUESTIONS_FILE = "questions.json" +STUDENTS_FILE = "students.json" \ No newline at end of file