谷歌硬盘客户端
drive的Python项目详细描述
驱动器
谷歌驱动客户端。
用法
api将客户端公开为drive.client.Client
,该客户端操作
drive.files.File
。File
表示一个google驱动器文件。注意两个
常规文件和目录表示为File
s,文件可以有
多个父目录。您可以使用
is_directory
属性。
注意:“文件夹”只是“目录”的同义词。
客户
高级Client
方法:
get_file(file_id)
(File
)get_file_by_name(name)
(File
)files_shared_with_me()
(File
列表)get_shared_directory(name)
(File
)root()
(File
)upload_file(parent, path[, name])
:上传文件upload_excel_workbook(parent, name, workbook)
:上传openpyxl
在名为name
的parent
下的谷歌电子表格中的工作簿。
客户端还公开处理文件id的低级方法。
文件
id
(str
,属性)name
(str
,属性)is_directory
(bool
,属性)human_type
(str
,属性):人类可读的文件类型exists()
(bool
)unlink()
(bool
):删除文件。如果它是一个目录,它的所有子目录 也会被删除rename(new_name)
:重命名文件move_in(new_parent[, new_name])
:将文件移动到另一个目录下。它 也可以同时重命名文件。list()
:列出目录的内容create_folder(name)
:在当前文件夹下创建一个文件夹get_or_create_folder(name)
:检索子文件夹或创建它 不存在get_child(name)
:返回当前目录下的文件。parents()
:返回文件的父级parent()
:返回文件的第一个父级download_file(path[, mime_type])
:在指定位置下载文件download_workbook()
:将文件作为openpyxl
工作簿下载json()
:将文件解析为jsonjsons()
:将文件解析为json(每行一个json),并返回一个生成器
在目录上操作的方法(例如list()
)通常在以下情况下无效
File
实例是常规文件。
示例
fromdrive.clientimportClient# Uses credentials from the path in the environment variable# GOOGLE_APPLICATION_CREDENTIALS.cl=Client()# Get the root directoryd=cl.root()print(d.is_directory)# Trueprint(d.name)# e.g. "My Drive"# Get a directory's contentforfind.list():print(f.name)# Get a shared directoryd=cl.get_shared_directory("My Shared Dir")
电子表格
cl=Client()# Downloadf=cl.get_file_by_name("my_sheet")workbook=f.download_workbook()# readonly openpyxl workbook# Uploadworkbook=Workbook()d=cl.get_shared_directory("My Shared Directory")cl.upload_excel_workbook(d,"my_other_sheet",workbook)
图纸
cl=Client()# download a Drawing in a png imagecl.download_file("11AASomeFileId","localfile.png","image/png")
许可证
cl=Client()# download a Drawing in a png imagecl.download_file("11AASomeFileId","localfile.png","image/png")
许可证
版权所有©2016-2019 oscaro.com
根据麻省理工学院的许可证发行。