From 772c7e7cd91ac2f3051fbeddf26038d6edc766fe Mon Sep 17 00:00:00 2001 From: timoxa0 Date: Fri, 20 Sep 2024 16:53:56 +0500 Subject: [PATCH] Enable test types 4, 5. Add file output. --- parse.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/parse.py b/parse.py index 5ae02ff..4dee337 100755 --- a/parse.py +++ b/parse.py @@ -11,6 +11,8 @@ LASTNAME = "Василий" CLASSTXT = "9А" TEST_ID = input("Enter test ID: ") +file = open(f"{TEST_ID}.txt", "w") +buffer = [] def begin_test(id: int, fisrstname: str, lastname: str, classtxt: str) -> dict: data = { @@ -73,6 +75,7 @@ complete_test(test_person['uuid']) for question in questions: print("Q:", BeautifulSoup( question["description"], "html.parser").text.replace("\n", ""), f"Type: {question['type']}") + buffer += [BeautifulSoup(question["description"], "html.parser").text.replace("\n", " ") + "\n"] if question['type'] == 1: with yaspin(text="Initializing", color="cyan") as sp: for i in range(len(question["answers"])): @@ -87,6 +90,7 @@ for question in questions: if complete_test(test_person['uuid']) == 1: sp.text = f"Answer: ✅ {question['answers'][i]['text']}" + buffer += [f"Answer: ✅ {question['answers'][i]['text']}\n"] sp.ok("Found!") break @@ -113,10 +117,11 @@ for question in questions: if complete_test(test_person['uuid']) == 1: msg = '\n'.join(map(lambda x: ' ✅ '+x, names)) sp.text = f"Answers: \n{msg}" + buffer += [f"Answers: \n{msg}\n"] sp.ok("Found!") break - elif (question["type"] == 4 or question["type"] == 5) and False: + elif (question["type"] == 4 or question["type"] == 5): with yaspin(text="Initializing", color="cyan") as sp: try: combs = list(itertools.product(range(1, len(json.loads(question["annotation"]))+1), repeat=len(question["answers"]))) @@ -145,6 +150,7 @@ for question in questions: if result == 1: msg = '\n'.join([f" {answer['answer']}) {answer['name']}" for answer in names]) sp.text = f"Answer: \n{msg}" + buffer += [f"Answers: \n{msg}\n"] sp.ok("Found!") executor.shutdown(wait=False, cancel_futures=True) break @@ -178,11 +184,14 @@ for question in questions: if complete_test(test_person['uuid']) == 1: msg = '\n'.join([f" {'✅ ' if answer['answer'] == 1 else '❌'} {answer['name']}" for answer in names]) sp.text = f"Answer: \n{msg}" + buffer += [f"Answers: \n{msg}\n"] sp.ok("Found!") break elif question["type"] in [3] : print("A: MANUAL") + buffer += [f"Answer: MANUAL\n"] print() - +file.writelines(buffer) +file.close() print("Test processing finished.")