WrightTools.google_drive module

Interact with google drive using the pydrive package.

class WrightTools.google_drive.Drive(account_id='default')[source]

Bases: object

Google Drive class.

__init__(account_id='default')[source]

init.

create_folder(name, parentid)[source]

Create a new folder in Google Drive.

name

string or list of string – Name of new folder to be created or list of new folders and subfolders.

parentID

string – Google Drive ID of folder that is to be the parent of new folder.

Returns:The unique Google Drive ID of the bottom-most newly created folder.
Return type:string
download(fileid, directory='cwd', overwrite=False, verbose=True)[source]

Recursively download from Google Drive into a local directory.

By default, will not re-download if file passes following checks:

  1. same size as remote file
  2. local file last modified after remote file
Parameters:
  • fileid (str) – Google drive id for file or folder.
  • directory (str (optional)) – Local directory to save content into. By default saves to cwd.
  • overwrite (bool (optional)) – Toggle forcing file overwrites. Default is False.
  • verbose (bool (optional)s) – Toggle talkback. Default is True.
Returns:

Return type:

pydrive.files.GoogleDriveFile

list_folder(folderid)[source]

List contents of a remote folder.

Parameters:folderid (string) – Folder ID.
Returns:List of contained IDs.
Return type:list of strings
upload(path, parentid, overwrite=False, delete_local=False, verbose=True)[source]

Upload local file(s) to Google Drive.

Parameters:
  • path (str) – Path to local file or folder.
  • parentid (str) – Google Drive ID of remote folder.
  • overwrite (bool (optional)) – Toggle forcing overwrite of remote files. Default is False.
  • delete_local (bool (optional)) – Toggle deleting local files and folders once uploaded. Default is False.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
Returns:

driveid – Google Drive ID of folder or file uploaded

Return type:

str

WrightTools.google_drive.id_to_url(driveid)[source]

Generate a url from a Google Drive id.

Parameters:id (string) – ID.
Returns:url.
Return type:string