3.1. gdoc_down package

3.1.1. Submodules

3.1.2. gdoc_down.__main__ module

Command line program to save the content of a Google document, presentation, or workbook to a local file in several formats.

Author

Jonathan Karr <karr@mssm.edu>

Date

2016-08-16

Copyright

2016, Karr Lab

License

MIT

class gdoc_down.__main__.App(credentials=None, **kwargs)[source]

Bases: cement.core.foundation.App

Command line application

class Meta[source]

Bases: object

base_controller = 'base'[source]
handlers = [<class 'gdoc_down.__main__.BaseController'>][source]
label = 'gdoc-down'[source]
class gdoc_down.__main__.BaseController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Base controller for command line application

class Meta[source]

Bases: object

arguments = [(['-v', '--version'], {'action': 'version', 'version': '0.0.10'}), (['google_file'], {'type': <class 'str'>, 'help': 'path to Google document, presentation, or workbook'}), (['--format', '-f'], {'type': <class 'str'>, 'help': 'output format (csv, docx, epub, html, odft, odp, ods, pdf, pptx, rtf, tsv, tex, txt, xlsx)', 'default': 'docx'}), (['--out_path', '-o'], {'type': <class 'str'>, 'help': 'path where Google document, presentation, or workbook should be downloaded', 'default': '.'}), (['--extension', '-e'], {'type': <class 'str'>, 'help': 'output extension', 'default': None})][source]
description = 'Download a Google document, presentation, or workbook to a local file'[source]
label = 'base'[source]
gdoc_down.__main__.main()[source]

3.1.3. gdoc_down._version module

3.1.4. gdoc_down.core module

Save the content of a Google document, presentation, or workbook to a local file.

Author

Jonathan Karr <karr@mssm.edu>

Date

2016-08-16

Copyright

2016, Karr Lab

License

MIT

class gdoc_down.core.GDocDown(credentials=None, service=None)[source]

Bases: object

Downloads Google documents, presentations, and workbooks to several formats

  • CSV (.csv)

  • EPUB (.epub)

  • Excel workbook (.xlsx)

  • HTML (.html)

  • LaTeX (.tex)

  • Open Office document (.odt)

  • Open Office presentation (.odp)

  • Open Office workbook (.ods)

  • Plain text file (.txt)

  • Portable document format (.pdf)

  • Powerpoint presentation (.pptx)

  • Rich text document (.rtf)

  • TSV (.tsv)

  • Word document (.docx)

The class has several special features for handling LaTeX files:

  • The program ignores all images. This allows the user to place images inside the Google document for convenience and to use \includegraphics to embed images in compile PDF files.

  • The program will convert all Google document comments to PDF comments.

  • The program ignores all page breaks.

The first time the program is called, the program will request access to the user’s Google account. This will create a client.json file.

credentials[source]

Credentials object for OAuth 2.0.

Type

oauth2client.client.OAuth2Credentials

service[source]

A Resource object with methods for interacting with the service

Type

apiclient.discovery.Resource

APPLICATION_NAME = 'gdoc_down'[source]
CLIENT_SECRET_PATH = '/root/project/gdoc_down/client.json'[source]
CREDENTIAL_PATH = '/root/.gdoc_down/auth.json'[source]
SCOPES = ('https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/drive.metadata.readonly', 'https://www.googleapis.com/auth/drive.readonly')[source]
authenticate(credentials)[source]

Authenticate with Google server

Returns

A Resource object with methods for interacting with the service

Return type

apiclient.discovery.Resource

classmethod convert_html_to_latex(html_zip_content)[source]

Format Google document content downloaded in HTML format for LaTeX

  • Replace HTML characters with LaTeX commands

  • Remove images

  • Replace comments with PDF comments (using pdfcomment package)

Parameters

html_zip_content (bytes) – HTML version of Google document

Returns

formatted LaTeX

Return type

bytes

download(google_file, format='docx', out_path='.', extension=None)[source]
Parameters
  • google_file (str) – path to Google document, presentation, or workbook

  • format (str, optional) – desired output format (docx, html, odt, pdf, rtf, tex, txt, etc)

  • out_path (str, optional) – path to save document, presentation, or workbook

  • extension (str, optional) – extension to document, presentation, or workbook

Raises

objException: if format unknown or if ouput file path and extension cannot both be specified

get_credentials()[source]

Get and save user credentials from Google. If credentials haven’t already been stored, or if the stored credentials are invalid, obtain the new credentials.

Retuns:

oauth2client.client.OAuth2Credentials: Credentials object for OAuth 2.0.

classmethod get_element_text(element)[source]

Get all of the text underneath an XML element

Parameters

el (xml.etree.ElementTree.Element) – XML element

Returns

element’s text

Return type

str

classmethod get_google_id(google_file)[source]

Get Google document, presentation, or workbook id

Parameters

google_file (str) – path to Google document, presentation, or workbook

Returns

id of Google document, presentation, or workbook

Return type

str

3.1.5. Module contents