From 70e442a97ef4315aa35ba41df41a9ce569f87e70 Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Fri, 24 Nov 2023 22:59:11 +0000 Subject: [PATCH] Actually save questions. --- app.py | 57 +++++++++++++-------------------- templates/question_templates.py | 8 ++--- 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/app.py b/app.py index 64ab055..b0896eb 100644 --- a/app.py +++ b/app.py @@ -166,15 +166,13 @@ def save_listening(): conversation_text_to_speech(part["text"]["conversation"], sound_file_path) else: text_to_speech(part["text"], sound_file_path) - # file_url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path) - file_url = "test_url/" + firebase_file_path + file_url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path) template["parts"][i]["audio"]["source"] = file_url template["parts"][i]["exercises"].append(part["exercises"]) - # if save_to_db("listening", template): - # return template - # else: - # raise Exception("Failed to save question: " + parts) - return template + if save_to_db("listening", template): + return template + else: + raise Exception("Failed to save question: " + parts) except Exception as e: return str(e) @@ -281,11 +279,10 @@ def save_writing_task(): template = getWritingTemplate() for i, exercise in enumerate(exercises, start=0): template["exercises"][i]["prompt"] = exercise - # if save_to_db("writing", template): - # return template - # else: - # raise Exception("Failed to save writing: " + template) - return template + if save_to_db("writing", template): + return template + else: + raise Exception("Failed to save writing: " + template) except Exception as e: return str(e) @@ -459,13 +456,11 @@ def save_speaking(): template = getSpeakingTemplate() # Speaking 1 - # sp1_result = create_video(exercises[0]["question"], random.choice(list(AvatarEnum))) - sp1_result = "speaking_1" + sp1_result = create_video(exercises[0]["question"], random.choice(list(AvatarEnum))) if sp1_result is not None: sound_file_path = VIDEO_FILES_PATH + sp1_result firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + sp1_result - # url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path) - url = "speaking_1_url" + url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path) sp1_video_path = firebase_file_path sp1_video_url = url template["exercises"][0]["text"] = exercises[0]["question"] @@ -476,13 +471,11 @@ def save_speaking(): print("Failed to create video for part 1 question: " + exercises[0]["question"]) # Speaking 2 - # sp2_result = create_video(exercises[1]["question"], random.choice(list(AvatarEnum))) - sp2_result = "speaking_2" + sp2_result = create_video(exercises[1]["question"], random.choice(list(AvatarEnum))) if sp2_result is not None: sound_file_path = VIDEO_FILES_PATH + sp2_result firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + sp2_result - # url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path) - url = "speaking_2_url" + url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path) sp2_video_path = firebase_file_path sp2_video_url = url template["exercises"][1]["prompts"] = exercises[1]["prompts"] @@ -497,13 +490,11 @@ def save_speaking(): sp3_questions = [] avatar = random.choice(list(AvatarEnum)) for question in exercises[2]["questions"]: - # result = create_video(question, avatar) - result = "speaking_3" + result = create_video(question, avatar) if result is not None: sound_file_path = VIDEO_FILES_PATH + result firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + result - # url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path) - url = "speaking_3_url" + url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path) video = { "text": question, "video_path": firebase_file_path, @@ -515,11 +506,10 @@ def save_speaking(): template["exercises"][2]["prompts"] = sp3_questions template["exercises"][2]["title"] = exercises[2]["topic"] - # if save_to_db("speaking", template): - # return template - # else: - # raise Exception("Failed to save speaking: " + template) - return template + if save_to_db("speaking", template): + return template + else: + raise Exception("Failed to save speaking: " + template) except Exception as e: return str(e) @@ -615,11 +605,10 @@ def save_reading_passage(): parts = data.get('parts') template = getReadingTemplate() template["parts"] = parts - # if save_to_db("reading", template): - # return template - # else: - # raise Exception("Failed to save reading: " + template) - return template + if save_to_db("reading", template): + return template + else: + raise Exception("Failed to save reading: " + template) except Exception as e: return str(e) diff --git a/templates/question_templates.py b/templates/question_templates.py index bfd98e7..719c37f 100644 --- a/templates/question_templates.py +++ b/templates/question_templates.py @@ -33,7 +33,7 @@ def getListeningTemplate(): "exercises": [] }, ], - "isDiagnostic": True, + "isDiagnostic": False, "minTimer": 30, "module": "listening" } @@ -715,7 +715,7 @@ def getListeningPostSample(): def getReadingTemplate(): return { "parts": [], - "isDiagnostic": True, + "isDiagnostic": False, "minTimer": 60, "type": "academic" } @@ -1179,7 +1179,7 @@ def getSpeakingTemplate(): "type": "interactiveSpeaking" } ], - "isDiagnostic": True, + "isDiagnostic": False, "minTimer": 14, "module": "speaking" } @@ -1241,7 +1241,7 @@ def getWritingTemplate(): } } ], - "isDiagnostic": True, + "isDiagnostic": False, "minTimer": 60, "module": "writing", "type": "general"