Skip to content

Commit

Permalink
fix: moving google docs back to root drive folder
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Hale <[email protected]>
  • Loading branch information
njhale committed Jan 30, 2025
1 parent 8e14fae commit 621f644
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions google/docs/move_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ def move_doc(drive_service, document_id, folder_path):
return

if folder_path.strip() == "/":
# Get the current parent folder(s)
file_metadata = drive_service.files().get(
fileId=document_id,
fields="parents"
).execute()
current_parents = ",".join(file_metadata.get("parents", []))

# Move the document back to the root folder
drive_service.files().update(
fileId=document_id,
addParents="root", # Add to the root folder
removeParents="root", # Ensure no redundant updates
addParents="root",
removeParents=current_parents,
fields="id, parents"
).execute()

print("Document moved back to the root folder.")
return

Expand Down
2 changes: 1 addition & 1 deletion google/docs/tool.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Share Tools: Create Google Doc
Share Context: Google Docs Context
Credential: ../credential
Param: doc_ref: Google Docs ID or share link of the document to read.
Param: doc_drive_dir: Optional folder path in Google Drive to move the document to after updating it. Use "/" to move the document back to the root folder.
Param: doc_drive_dir: Optional folder path in Google Drive to move the document to after updating it. Use `/` to move the document back to the root folder.
Param: doc_content: Markdown formatted content to replace the existing content of the document with.

#!/usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/update_doc.py
Expand Down

0 comments on commit 621f644

Please sign in to comment.