in genai-for-marketing/backend_apis/app/utils_workspace.py [0:0]
def create_doc(
credentials,
folder_id: str,
doc_name: str,
text: str):
docs_service = build('docs', 'v1', credentials=credentials)
title = doc_name
body = {
'title': title
}
doc = docs_service.documents().create(body=body).execute(num_retries=20)
title = doc.get('title')
_id = doc.get('documentId')
print(f'Created document with title: {title}, id: {_id}')
# Text insertion
requests = [
{
'insertText': {
'location': {
'index': 1,
},
'text': text
}
}
]
docs_service.documents().batchUpdate(documentId=_id, body={'requests': requests}).execute(num_retries=20)
move_drive_file(credentials=credentials,drive_file_id=_id,parentFolderId=folder_id,copy_title=title)
return _id