From 545052d1aaba27b5fce205b1a45e9a93b2d1919e Mon Sep 17 00:00:00 2001 From: mgeld Date: Mon, 13 Jul 2026 02:38:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BB=D1=83=D0=B6=D0=B5=D0=B1=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B2=D0=BE=D0=BF=D1=80=D0=BE=D1=81=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check_questions.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 check_questions.py diff --git a/check_questions.py b/check_questions.py new file mode 100644 index 0000000..f42f12b --- /dev/null +++ b/check_questions.py @@ -0,0 +1,34 @@ +# Служебная проверка данных викторины: у каждого вопроса 4 варианта, +# номер правильного ответа существует, тексты не пустые. +# Запуск: python check_questions.py +import re +import sys + +with open("questions.js", encoding="utf-8") as f: + src = f.read() + +texts = re.findall(r'text:\s*"([^"]*)"', src) +options_blocks = re.findall(r'options:\s*\[([^\]]*)\]', src) +corrects = [int(m) for m in re.findall(r'correct:\s*(\d+)', src)] + +errors = [] + +if not (len(texts) == len(options_blocks) == len(corrects)): + errors.append("У какого-то вопроса не хватает поля (text/options/correct).") + +for n, (text, block, correct) in enumerate(zip(texts, options_blocks, corrects), 1): + opts = re.findall(r'"([^"]*)"', block) + if not text.strip(): + errors.append(f"Вопрос {n}: пустой текст.") + if len(opts) != 4: + errors.append(f"Вопрос {n}: вариантов {len(opts)}, а нужно 4.") + if not (0 <= correct < len(opts)): + errors.append(f"Вопрос {n}: correct={correct} указывает мимо вариантов.") + +if errors: + print("ПРОБЛЕМЫ:") + for e in errors: + print(" -", e) + sys.exit(1) + +print(f"OK: {len(texts)} вопросов, у всех 4 варианта и правильный ответ на месте.")