diff --git a/app.py b/app.py index f78fee5..237fe3a 100644 --- a/app.py +++ b/app.py @@ -167,6 +167,8 @@ def save_listening(): template = getListeningTemplate() id = str(uuid.uuid4()) for i, part in enumerate(parts, start=0): + part_template = getListeningPartTemplate() + file_name = str(uuid.uuid4()) + ".mp3" sound_file_path = AUDIO_FILES_PATH + file_name firebase_file_path = FIREBASE_LISTENING_AUDIO_FILES_PATH + file_name @@ -175,8 +177,11 @@ def save_listening(): else: text_to_speech(part["text"], sound_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"] = part["exercises"] + + part_template["audio"]["source"] = file_url + part_template["exercises"] = part["exercises"] + + template['parts'].append(part_template) if minTimer != LISTENING_MIN_TIMER_DEFAULT: template["minTimer"] = minTimer diff --git a/templates/question_templates.py b/templates/question_templates.py index a36b466..b065626 100644 --- a/templates/question_templates.py +++ b/templates/question_templates.py @@ -2,39 +2,18 @@ import uuid from helper.constants import * +def getListeningPartTemplate(): + return { + "audio": { + "repeatableTimes": 3, + "source": "", + }, + "exercises": [] + } def getListeningTemplate(): return { - "parts": [ - { - "audio": { - "repeatableTimes": 3, - "source": "", - }, - "exercises": [] - }, - { - "audio": { - "repeatableTimes": 3, - "source": "", - }, - "exercises": [] - }, - { - "audio": { - "repeatableTimes": 3, - "source": "", - }, - "exercises": [] - }, - { - "audio": { - "repeatableTimes": 3, - "source": "", - }, - "exercises": [] - }, - ], + "parts": [], "isDiagnostic": False, "minTimer": LISTENING_MIN_TIMER_DEFAULT, "module": "listening"