Updated the Listening template to allow for a dynamic amount of parts
This commit is contained in:
9
app.py
9
app.py
@@ -167,6 +167,8 @@ def save_listening():
|
|||||||
template = getListeningTemplate()
|
template = getListeningTemplate()
|
||||||
id = str(uuid.uuid4())
|
id = str(uuid.uuid4())
|
||||||
for i, part in enumerate(parts, start=0):
|
for i, part in enumerate(parts, start=0):
|
||||||
|
part_template = getListeningPartTemplate()
|
||||||
|
|
||||||
file_name = str(uuid.uuid4()) + ".mp3"
|
file_name = str(uuid.uuid4()) + ".mp3"
|
||||||
sound_file_path = AUDIO_FILES_PATH + file_name
|
sound_file_path = AUDIO_FILES_PATH + file_name
|
||||||
firebase_file_path = FIREBASE_LISTENING_AUDIO_FILES_PATH + file_name
|
firebase_file_path = FIREBASE_LISTENING_AUDIO_FILES_PATH + file_name
|
||||||
@@ -175,8 +177,11 @@ def save_listening():
|
|||||||
else:
|
else:
|
||||||
text_to_speech(part["text"], sound_file_path)
|
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 = 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:
|
if minTimer != LISTENING_MIN_TIMER_DEFAULT:
|
||||||
template["minTimer"] = minTimer
|
template["minTimer"] = minTimer
|
||||||
|
|||||||
@@ -2,39 +2,18 @@ import uuid
|
|||||||
|
|
||||||
from helper.constants import *
|
from helper.constants import *
|
||||||
|
|
||||||
|
def getListeningPartTemplate():
|
||||||
|
return {
|
||||||
|
"audio": {
|
||||||
|
"repeatableTimes": 3,
|
||||||
|
"source": "",
|
||||||
|
},
|
||||||
|
"exercises": []
|
||||||
|
}
|
||||||
|
|
||||||
def getListeningTemplate():
|
def getListeningTemplate():
|
||||||
return {
|
return {
|
||||||
"parts": [
|
"parts": [],
|
||||||
{
|
|
||||||
"audio": {
|
|
||||||
"repeatableTimes": 3,
|
|
||||||
"source": "",
|
|
||||||
},
|
|
||||||
"exercises": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"audio": {
|
|
||||||
"repeatableTimes": 3,
|
|
||||||
"source": "",
|
|
||||||
},
|
|
||||||
"exercises": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"audio": {
|
|
||||||
"repeatableTimes": 3,
|
|
||||||
"source": "",
|
|
||||||
},
|
|
||||||
"exercises": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"audio": {
|
|
||||||
"repeatableTimes": 3,
|
|
||||||
"source": "",
|
|
||||||
},
|
|
||||||
"exercises": []
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"isDiagnostic": False,
|
"isDiagnostic": False,
|
||||||
"minTimer": LISTENING_MIN_TIMER_DEFAULT,
|
"minTimer": LISTENING_MIN_TIMER_DEFAULT,
|
||||||
"module": "listening"
|
"module": "listening"
|
||||||
|
|||||||
Reference in New Issue
Block a user