Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable moving files to folder IDs as well as names #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions gspread_pandas/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def create_folder(self, path, parents=True):
self.refresh_directories()
return parent

def move_file(self, file_id, path, create=False):
def move_file(self, file_id, path, id_string, create=False):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id_string here is the folder id, right? if so, I think folder_id would be more descriptive (id_string indicates it's an ID and a string, but it's not clear an id for what).

Since folder_id becomes an alternative to path, we should make both parameters optional with a default of None and a check that at least one of them is provided.

"""
Move a file to the given path.

Expand All @@ -400,16 +400,20 @@ def move_file(self, file_id, path, create=False):
Returns
-------
"""
if path == "/":
folder_id = "root"
if id_string:
folder_id = id_string

else:
parent, missing = folders_to_create(path, self._get_dirs(False))
if missing:
if not create:
raise Exception("Folder does not exist")
if path == "/":
folder_id = "root"
else:
parent, missing = folders_to_create(path, self._get_dirs(False))
if missing:
if not create:
raise Exception("Folder does not exist")

parent = self.create_folder(path)
folder_id = parent["id"]
parent = self.create_folder(path)
folder_id = parent["id"]

old_parents = self._drive_request(
"get", file_id, params={"fields": "parents"}
Expand Down
4 changes: 2 additions & 2 deletions gspread_pandas/spread.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ def list_permissions(self):
"""
return self.client.list_permissions(self.spread.id)

def move(self, path="/", create=True):
def move(self, path="/", id_string=None, create=True):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, should be named folder_id

"""
Move the current spreadsheet to the specified path in your Google drive. If the
file is not currently in you drive, it will be added.
Expand All @@ -1027,4 +1027,4 @@ def move(self, path="/", create=True):
Returns
-------
"""
self.client.move_file(self.spread.id, path, create)
self.client.move_file(self.spread.id, path, id_string, create)