google drive命令行工具

gdcmdtools3的Python项目详细描述


状态

Build Status

PYPI

新功能

  • 0.98分
    • 添加了gdrm.py,能够删除文件和文件夹。

GDCMDTools

google drive命令行工具

在google驱动器上维护文件的工具。

功能

安装

  • 检查系统是否安装了python
    • gdcmdtools是在python 2.7.3下开发的,我建议用户使用python2.7.3运行这些工具(ok:2.7.2)
  • 皮普
    • 对于Mac OSX
      1. sudo easy_安装pip
      2. sudo pip安装google api python客户端
      3. sudo pip安装gdcmdtools
    • 对于ubuntu linux
      1. sudo apt get install python pip
      2. sudo pip安装google api python客户端
      3. sudo pip安装gdcmdtools
    • 安装之后,您将在/usr/local/bin下看到gd*.py。
  • ubuntu Linux购电协议
    1. sudo apt add repository ppa:ctf/gdcmdtools
    2. sudo apt get update
    3. sudo apt get安装python gdcmdtools

API设置

  • 为该工具创建一个新项目以访问您的google驱动器

  • 在“api&auth/api”中启用以下google api

    • 驱动器API
    • 融合表api
  • 确保您的应用程序在“api&auth/credentials/oauthconcept screen”中有一个应用程序名

    • 找到“产品名称”字段。确保不是空白。
  • 在“api&auth/credentials”中授予对google drive for gdcmdtools的访问权限

    1. 单击“创建新客户端ID”,应用程序类型:已安装的应用程序,已安装的应用程序类型:其他
    2. 检查“本地应用程序的客户端ID”部分,单击“下载JSON”。
    3. 在终端中执行gdauth.py并将下载的机密文件作为参数:$gdauth.py client_secrets.json
    4. 您将看到如下消息:info:gdcmdtools.base:请访问浏览器中的URL:https://accounts.google.com/o/oauth2/auth?scope=….
    5. 使用浏览器访问url并允许应用程序访问您的google驱动器。
    6. 复制您在浏览器中看到的代码,然后返回到终端,粘贴代码并按回车键。
    7. 完成,除非凭据过期,否则不会再次要求您输入代码。

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Rest DSL路由无法启动路由,因为同一端点不允许有多个使用者   jvm有没有像JConsole或VisualVM这样的工具可以告诉我“类、对象、引用变量在java中存储在哪里?”   java为什么我的列表中的所有元素看起来都一样?   java运行时。运行shell脚本的exec无法打开文件   JPopupMenu的JMenuItem的java热键   会话在Java中被覆盖   如何在java中去除字符串中的尖锐重音?   java Mockito监视一个接口,模拟它的默认方法,获取NullPointerException   javascript如何在jquery中禁用同一时间选择   将数组列表附加到现有CSV文件,但它会附加并清除存储在Java文件中的以前的数据   java从我的jar中访问pdf文件   java Sonar issue参数必须为非Null,但标记为可为Null   java Salesforce流式API:在网络故障之后和重新订阅之前获取事件   在Java 1.8.0_65上运行Play2.0应用程序时出现playframework错误   java为什么字母的ASCII由方法自动转换。toCharArray()?   java如何知道JDialog是否关闭?   java向服务器发送POST请求,服务器的响应为null,启动   java如何设置JTable中特定单元格的值?   ImagePlus中的java保存问题