Replace logging with app.logger.
This commit is contained in:
@@ -38,7 +38,7 @@ TYLER_CHRISTOPHER = "03c796f8ed274bb38f19e893bcbc6121"
|
||||
|
||||
def create_videos_and_save_to_db(exercises, template, id):
|
||||
# Speaking 1
|
||||
logging.info('Creating video for speaking part 1')
|
||||
app.app.logger.info('Creating video for speaking part 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
|
||||
@@ -51,10 +51,10 @@ def create_videos_and_save_to_db(exercises, template, id):
|
||||
template["exercises"][0]["video_url"] = sp1_video_url
|
||||
template["exercises"][0]["video_path"] = sp1_video_path
|
||||
else:
|
||||
logging.error("Failed to create video for part 1 question: " + exercises[0]["question"])
|
||||
app.app.logger.error("Failed to create video for part 1 question: " + exercises[0]["question"])
|
||||
|
||||
# Speaking 2
|
||||
logging.info('Creating video for speaking part 2')
|
||||
app.app.logger.info('Creating video for speaking part 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
|
||||
@@ -68,12 +68,12 @@ def create_videos_and_save_to_db(exercises, template, id):
|
||||
template["exercises"][1]["video_url"] = sp2_video_url
|
||||
template["exercises"][1]["video_path"] = sp2_video_path
|
||||
else:
|
||||
logging.error("Failed to create video for part 2 question: " + exercises[1]["question"])
|
||||
app.app.logger.error("Failed to create video for part 2 question: " + exercises[1]["question"])
|
||||
|
||||
# Speaking 3
|
||||
sp3_questions = []
|
||||
avatar = random.choice(list(AvatarEnum))
|
||||
logging.info('Creating videos for speaking part 3')
|
||||
app.app.logger.info('Creating videos for speaking part 3')
|
||||
for question in exercises[2]["questions"]:
|
||||
result = create_video(question, avatar)
|
||||
if result is not None:
|
||||
@@ -87,7 +87,7 @@ def create_videos_and_save_to_db(exercises, template, id):
|
||||
}
|
||||
sp3_questions.append(video)
|
||||
else:
|
||||
logging.error("Failed to create video for part 3 question: " + question)
|
||||
app.app.logger.error("Failed to create video for part 3 question: " + question)
|
||||
template["exercises"][2]["prompts"] = sp3_questions
|
||||
template["exercises"][2]["title"] = exercises[2]["topic"]
|
||||
|
||||
@@ -109,8 +109,8 @@ def create_video(text, avatar: AvatarEnum):
|
||||
]
|
||||
}
|
||||
response = requests.post(CREATE_VIDEO_URL, headers=POST_HEADER, json=data)
|
||||
logging.info(response.status_code)
|
||||
logging.info(response.json())
|
||||
app.app.logger.info(response.status_code)
|
||||
app.app.logger.info(response.json())
|
||||
|
||||
# GET TO CHECK STATUS AND GET VIDEO WHEN READY
|
||||
video_id = response.json()["data"]["video_id"]
|
||||
@@ -129,11 +129,11 @@ def create_video(text, avatar: AvatarEnum):
|
||||
error = response_data["data"]["error"]
|
||||
|
||||
if status != "completed" and error is None:
|
||||
logging.info(f"Status: {status}")
|
||||
app.app.logger.info(f"Status: {status}")
|
||||
time.sleep(5) # Wait for 5 second before the next request
|
||||
|
||||
logging.info(response.status_code)
|
||||
logging.info(response.json())
|
||||
app.app.logger.info(response.status_code)
|
||||
app.app.logger.info(response.json())
|
||||
|
||||
# DOWNLOAD VIDEO
|
||||
download_url = response.json()['data']['video_url']
|
||||
@@ -147,8 +147,8 @@ def create_video(text, avatar: AvatarEnum):
|
||||
output_path = os.path.join(output_directory, output_filename)
|
||||
with open(output_path, 'wb') as f:
|
||||
f.write(response.content)
|
||||
logging.info(f"File '{output_filename}' downloaded successfully.")
|
||||
app.app.logger.info(f"File '{output_filename}' downloaded successfully.")
|
||||
return output_filename
|
||||
else:
|
||||
logging.error(f"Failed to download file. Status code: {response.status_code}")
|
||||
app.app.logger.error(f"Failed to download file. Status code: {response.status_code}")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user