google drive命令行工具
gdcmdtools3的Python项目详细描述
状态
PYPI
新功能
- 0.98分
- 添加了gdrm.py,能够删除文件和文件夹。
GDCMDTools
google drive命令行工具
在google驱动器上维护文件的工具。
功能
- 下载/上传文件到谷歌硬盘
- 上传应用程序脚本项目(gas)
- 使用Google Drive REST API V2
安装
- 检查系统是否安装了python
- gdcmdtools是在python 2.7.3下开发的,我建议用户使用python2.7.3运行这些工具(ok:2.7.2)
- 皮普
- 对于Mac OSX
- sudo easy_安装pip
- sudo pip安装google api python客户端
- sudo pip安装gdcmdtools
- 对于ubuntu linux
- sudo apt get install python pip
- sudo pip安装google api python客户端
- sudo pip安装gdcmdtools
- 安装之后,您将在/usr/local/bin下看到gd*.py。
- 对于Mac OSX
- ubuntu Linux购电协议
- sudo apt add repository ppa:ctf/gdcmdtools
- sudo apt get update
- sudo apt get安装python gdcmdtools
API设置
为该工具创建一个新项目以访问您的google驱动器
- 访问https://console.developers.google.com/,创建项目,随意命名,例如:gdcmdtools。
在“api&auth/api”中启用以下google api
- 驱动器API
- 融合表api
确保您的应用程序在“api&auth/credentials/oauthconcept screen”中有一个应用程序名
- 找到“产品名称”字段。确保不是空白。
在“api&auth/credentials”中授予对google drive for gdcmdtools的访问权限
- 单击“创建新客户端ID”,应用程序类型:已安装的应用程序,已安装的应用程序类型:其他
- 检查“本地应用程序的客户端ID”部分,单击“下载JSON”。
- 在终端中执行gdauth.py并将下载的机密文件作为参数:$gdauth.py client_secrets.json
- 您将看到如下消息:info:gdcmdtools.base:请访问浏览器中的URL:https://accounts.google.com/o/oauth2/auth?scope=….
- 使用浏览器访问url并允许应用程序访问您的google驱动器。
- 复制您在浏览器中看到的代码,然后返回到终端,粘贴代码并按回车键。
- 完成,除非凭据过期,否则不会再次要求您输入代码。
Gdauth
使用该工具通过OAuth2身份验证
使用量
usage: gdauth.py [-h] [-r {local,oob}] secret_file gdauth v0.0.1 - Google Drive OAuth2 authentication tool - gdcmdtools (Google Drive command line tools) positional arguments: secret_file the secret file in JSON format, ~/.gdcmdtools.secrets will be overwritten optional arguments: -h, --help show this help message and exit -r {local,oob}, --redirect_uri {local,oob} specify the redirect URI for the oauth2 flow, could be: local: means "http://localhost" oob: (default) means "urn:ietf:wg:oauth:2.0:oob"
gdauth
的示例% python ./gdauth.py /tmp/client_secrets.json # Use the /tmp/client_secrets.json as secret file
GDPUT
此工具可用于将文件作为电子表格、csv、fusion table、doc等上传到google drive。
使用量
usage: gdput.py [-h] [-s SOURCE_TYPE] [-l TARGET_TITLE] [-d TARGET_DESCRIPTION] [--no_print_id] [-f FOLDER_ID] [--debug {debug,info,warning,error,critical}] [-p TYPE ROLE VALUE] [-t {raw,ft,pt,ss,doc,ocr,dr,gas}] [--ft_latlng_column FT_LATLNG_COLUMN] [--ft_location_column FT_LOCATION_COLUMN] [--csv_column_define define1_define2_defineN...] source_file gdput v0.91 - Tool to upload file to Google Drive - gdcmdtools (Google Drive command line tools) positional arguments: source_file The file you're going to upload to Google Drive optional arguments: -h, --help show this help message and exit -s SOURCE_TYPE, --source_type SOURCE_TYPE define the source file type by MIME type, ex: "text/csv", or "auto" to determine the file type by file name -l TARGET_TITLE, --target_title TARGET_TITLE specify the title of the target file -d TARGET_DESCRIPTION, --target_description TARGET_DESCRIPTION specify the description of the target file --no_print_id set if you like not to print the file id after file being uploaded -f FOLDER_ID, --folder_id FOLDER_ID the target folder ID on the Google drive --debug {debug,info,warning,error,critical} define the debug level -p TYPE ROLE VALUE, --permission TYPE ROLE VALUE set the permission of the uploaded file, can be: type: user, group, domain, anyone role: owner, reader, writer value: user or group e-mail address, or 'me' to refer to the current authorized user ex: -p anyone reader me # set the uploaded file public-read -t {raw,ft,pt,ss,doc,ocr,dr,gas}, --target_type {raw,ft,pt,ss,doc,ocr,dr,gas} define the target file type on Google Drive, can be: raw: (default) the source file will uploaded without touching ft: Fusion Table (for .csv) pt: Presentation (for .ppt, .pps, .pptx) ss: Spreadsheet (for .xls, .xlsx, .ods, .csv, .tsv, .tab) doc: Document (for .doc, .docx, .html, .htm, .txt, .rtf) ocr: OCR (for .jpg, .git, .png, .pdf) dr: Drawing (for .wmf) gas: GAS project (for .json) fusion table support (--target_type ft): --ft_latlng_column FT_LATLNG_COLUMN specify the column header for latitude and longitude for the fusion table, the column will be created automatically --ft_location_column FT_LOCATION_COLUMN specify the location column header for the fusion table --csv_column_define define1_define2_defineN... define the columns type for each column of the csv file, can be "string", "number", "datetime", or "location". ex: has 4 columns in the csv file: "name", "age", "birthday", "address". you can set --csv_column_define string_number_datetime_location
gdput
的示例% python ./gdput.py photo.jpg # upload photo.jpg to gd without changing the format
% python ./gdput.py -t ft samples/sample.csv # upload a csv file to gd as fusion table
% python ./gdput.py -t ss samples/sample.csv # upload a csv file to gd as spreadsheet
% python ./gdput.py -t ft --ft_location_column address --ft_latlng_column latlng samples/sample.csv
# upload a csv to gd as fusion table with geocoding the latitude longitude data according to the address rows
% python ./gdput.py -p anyone reader me samples/sample.csv
# upload a csv file as Spreadsheet and set the file public-read
% python ./gdput.py -t ft --csv_column_define string_string_location_string_string_number samples/sample.csv
# upload a csv file as ft with specifed column type
% python ./gdput.py -t gas gas_project.json
# update gas project with project file 'gas_project.json'
gdget
从Google Drive获取文件
使用量
usage: gdget.py [-h] [-f FORMAT] [-s NEW_FILE_NAME] [--debug {debug,info,warning,error,critical}] file_id gdget v0.91 - Tool to download file from Google Drive - gdcmdtools (Google Drive command line tools) positional arguments: file_id The id for the file you're going to download optional arguments: -h, --help show this help message and exit -f FORMAT, --export_format FORMAT specify the export format for downloading, google_format: export_format spreadsheet: pdf, ods, xlsx drawing: png, pdf, jpeg, svg document: pdf, docx, rtf, odt, html, txt script+json: json presentation: pdf, pptx, txt -s NEW_FILE_NAME, --save_as NEW_FILE_NAME save the downloaded file as --debug {debug,info,warning,error,critical} define the debug level
gdget
的示例% python ./gdget.py FILE_ID --export_format pdf -s /tmp/myfile.pdf # export the file as pdf and save as /tmp/myfile.pdf
% python ./gdget.py FILE_ID -f json # down files associated with GAS project
gdperm
此工具可用于设置文件权限
使用量
usage: gdperm.py [-h] [--list | --get PERMISSION_ID | --insert TYPE ROLE VALUE | --delete PERMISSION_ID] file_id gdperm v0.0.1 - Tool to change file's permission on Google Drive - gdcmdtools (Google Drive command line tools) positional arguments: file_id The id of file you're going to change permission optional arguments: -h, --help show this help message and exit --list list the permission resource of the file --get PERMISSION_ID get the permission resource by id --insert TYPE ROLE VALUE insert the permission to the file by id --delete PERMISSION_ID delete the permission of the file by id
gdperm
的示例% python ./gdperm.py 0B_XXXXXXXXXX --insert anyone reader me # set the file as public-read
% python ./gdperm.py 0B_XXXXXXXXXX --list # list the permissions by file id: 0B_XXXXXXXXXX
% python ./gdperm.py 0B_XXXXXXXXXX --get 5566520 # get the permissions by permission id: 5566520
% python ./gdperm.py 0B_XXXXXXXXXX --delete 5566520 # delete the permissions by permission id: 5566520
套餐
许可证
BSD 2条款许可证
错误
请通过https://github.com/tienfuc/gdcmdtools/issues报告错误
作者
陈天福
电子邮箱:tienfu.c@gmail.com