From 34154b1e5fcec5354a80d1d1e3009ee90521ba0f Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Wed, 29 Nov 2023 15:44:39 +0000 Subject: [PATCH] Another try --- app.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 6c17910..88a01ff 100644 --- a/app.py +++ b/app.py @@ -169,8 +169,10 @@ def save_listening(): 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"] - if save_to_db("listening", template): - return template + + (result, id) = save_to_db("listening", template) + if result: + return {**template, "id": id} else: raise Exception("Failed to save question: " + parts) except Exception as e: @@ -279,8 +281,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 + + (result, id) = save_to_db("writing", template) + if result: + return {**template, "id": id} else: raise Exception("Failed to save writing: " + template) except Exception as e: @@ -505,9 +509,10 @@ def save_speaking(): print("Failed to create video for part 3 question: " + question) template["exercises"][2]["prompts"] = sp3_questions template["exercises"][2]["title"] = exercises[2]["topic"] - - if save_to_db("speaking", template): - return template + + (result, id) = save_to_db("speaking", template) + if result: + return {**template, "id": id} else: raise Exception("Failed to save speaking: " + template) except Exception as e: @@ -605,8 +610,10 @@ def save_reading_passage(): parts = data.get('parts') template = getReadingTemplate() 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: raise Exception("Failed to save reading: " + template) except Exception as e: