Enable test types 4, 5. Add file output.

This commit is contained in:
timoxa0 2024-09-20 16:53:56 +05:00
parent d0d3697776
commit 772c7e7cd9

View file

@ -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.")