Merge remote-tracking branch 'origin/master'
This commit is contained in:
27
app.py
27
app.py
@@ -168,9 +168,11 @@ def save_listening():
|
|||||||
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]["audio"]["source"] = file_url
|
||||||
template["parts"][i]["exercises"].append(part["exercises"])
|
template["parts"][i]["exercises"] = part["exercises"]
|
||||||
if save_to_db("listening", template):
|
|
||||||
return template
|
(result, id) = save_to_db("listening", template)
|
||||||
|
if result:
|
||||||
|
return {**template, "id": id}
|
||||||
else:
|
else:
|
||||||
raise Exception("Failed to save question: " + parts)
|
raise Exception("Failed to save question: " + parts)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -292,8 +294,10 @@ def save_writing_task():
|
|||||||
template = getWritingTemplate()
|
template = getWritingTemplate()
|
||||||
for i, exercise in enumerate(exercises, start=0):
|
for i, exercise in enumerate(exercises, start=0):
|
||||||
template["exercises"][i]["prompt"] = exercise
|
template["exercises"][i]["prompt"] = exercise
|
||||||
if save_to_db("writing", template):
|
|
||||||
return template
|
(result, id) = save_to_db("writing", template)
|
||||||
|
if result:
|
||||||
|
return {**template, "id": id}
|
||||||
else:
|
else:
|
||||||
raise Exception("Failed to save writing: " + template)
|
raise Exception("Failed to save writing: " + template)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -518,9 +522,10 @@ def save_speaking():
|
|||||||
print("Failed to create video for part 3 question: " + question)
|
print("Failed to create video for part 3 question: " + question)
|
||||||
template["exercises"][2]["prompts"] = sp3_questions
|
template["exercises"][2]["prompts"] = sp3_questions
|
||||||
template["exercises"][2]["title"] = exercises[2]["topic"]
|
template["exercises"][2]["title"] = exercises[2]["topic"]
|
||||||
|
|
||||||
if save_to_db("speaking", template):
|
(result, id) = save_to_db("speaking", template)
|
||||||
return template
|
if result:
|
||||||
|
return {**template, "id": id}
|
||||||
else:
|
else:
|
||||||
raise Exception("Failed to save speaking: " + template)
|
raise Exception("Failed to save speaking: " + template)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -619,8 +624,10 @@ def save_reading_passage():
|
|||||||
parts = data.get('parts')
|
parts = data.get('parts')
|
||||||
template = getReadingTemplate()
|
template = getReadingTemplate()
|
||||||
template["parts"] = parts
|
template["parts"] = parts
|
||||||
if save_to_db("reading", template):
|
|
||||||
return template
|
(result, id) = save_to_db("reading", template)
|
||||||
|
if result:
|
||||||
|
return {**template, "id": id}
|
||||||
else:
|
else:
|
||||||
raise Exception("Failed to save reading: " + template)
|
raise Exception("Failed to save reading: " + template)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ def upload_file_firebase_get_url(bucket_name, destination_blob_name, source_file
|
|||||||
def save_to_db(collection: str, item):
|
def save_to_db(collection: str, item):
|
||||||
db = firestore.client()
|
db = firestore.client()
|
||||||
collection_ref = db.collection(collection)
|
collection_ref = db.collection(collection)
|
||||||
document_ref = collection_ref.add(item)
|
(update_time, document_ref) = collection_ref.add(item)
|
||||||
if document_ref:
|
if document_ref:
|
||||||
print(f"Document added with ID: {document_ref}")
|
print(f"Document added with ID: {document_ref.id}")
|
||||||
return True
|
return (True, document_ref.id)
|
||||||
else:
|
else:
|
||||||
return False
|
return (False, None)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user