Replace prints with proper logs.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
|
||||
@@ -5,6 +6,8 @@ import requests
|
||||
import time
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import app
|
||||
from helper.constants import *
|
||||
from helper.firebase_helper import upload_file_firebase_get_url, save_to_db_with_id
|
||||
from heygen.AvatarEnum import AvatarEnum
|
||||
@@ -35,6 +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')
|
||||
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
|
||||
@@ -47,9 +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:
|
||||
print("Failed to create video for part 1 question: " + exercises[0]["question"])
|
||||
logging.error("Failed to create video for part 1 question: " + exercises[0]["question"])
|
||||
|
||||
# Speaking 2
|
||||
logging.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
|
||||
@@ -63,11 +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:
|
||||
print("Failed to create video for part 2 question: " + exercises[1]["question"])
|
||||
logging.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')
|
||||
for question in exercises[2]["questions"]:
|
||||
result = create_video(question, avatar)
|
||||
if result is not None:
|
||||
@@ -81,7 +87,7 @@ def create_videos_and_save_to_db(exercises, template, id):
|
||||
}
|
||||
sp3_questions.append(video)
|
||||
else:
|
||||
print("Failed to create video for part 3 question: " + question)
|
||||
logging.error("Failed to create video for part 3 question: " + question)
|
||||
template["exercises"][2]["prompts"] = sp3_questions
|
||||
template["exercises"][2]["title"] = exercises[2]["topic"]
|
||||
|
||||
@@ -103,8 +109,8 @@ def create_video(text, avatar: AvatarEnum):
|
||||
]
|
||||
}
|
||||
response = requests.post(CREATE_VIDEO_URL, headers=POST_HEADER, json=data)
|
||||
print(response.status_code)
|
||||
print(response.json())
|
||||
logging.info(response.status_code)
|
||||
logging.info(response.json())
|
||||
|
||||
# GET TO CHECK STATUS AND GET VIDEO WHEN READY
|
||||
video_id = response.json()["data"]["video_id"]
|
||||
@@ -123,11 +129,11 @@ def create_video(text, avatar: AvatarEnum):
|
||||
error = response_data["data"]["error"]
|
||||
|
||||
if status != "completed" and error is None:
|
||||
print(f"Status: {status}")
|
||||
logging.info(f"Status: {status}")
|
||||
time.sleep(5) # Wait for 5 second before the next request
|
||||
|
||||
print(response.status_code)
|
||||
print(response.json())
|
||||
logging.info(response.status_code)
|
||||
logging.info(response.json())
|
||||
|
||||
# DOWNLOAD VIDEO
|
||||
download_url = response.json()['data']['video_url']
|
||||
@@ -141,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)
|
||||
print(f"File '{output_filename}' downloaded successfully.")
|
||||
logging.info(f"File '{output_filename}' downloaded successfully.")
|
||||
return output_filename
|
||||
else:
|
||||
print(f"Failed to download file. Status code: {response.status_code}")
|
||||
logging.error(f"Failed to download file. Status code: {response.status_code}")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user