-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a handler for get_audiocast by session_id
- Loading branch information
1 parent
87c4f04
commit dd23c9d
Showing
2 changed files
with
47 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from datetime import datetime | ||
|
||
from fastapi import HTTPException | ||
|
||
from services.storage import StorageManager | ||
from src.utils.generate_audiocast import ( | ||
GenerateAudioCastResponse, | ||
) | ||
from utils_pkg.session_manager import SessionManager | ||
|
||
|
||
def get_audiocast(session_id: str): | ||
""" | ||
Get audiocast based on session id | ||
""" | ||
storage_manager = StorageManager() | ||
filepath = storage_manager.download_from_gcs(session_id) | ||
|
||
session_data = SessionManager(session_id).data() | ||
if not session_data: | ||
raise HTTPException( | ||
status_code=404, | ||
detail=f"Audiocast not found for session_id: {session_id}", | ||
) | ||
|
||
metadata = session_data.metadata | ||
source = metadata.source if metadata else "" | ||
transcript = metadata.transcript if metadata else "" | ||
|
||
created_at = None | ||
if session_data.created_at: | ||
created_at = datetime.fromisoformat(session_data.created_at).strftime( | ||
"%Y-%m-%d %H:%M" | ||
) | ||
|
||
return GenerateAudioCastResponse( | ||
url=filepath, | ||
script=transcript, | ||
source_content=source, | ||
created_at=created_at, | ||
) |