Note that there are some explanatory texts on larger screens.

plurals
  1. PODownload a spreadsheet from Google Docs using Python
    primarykey
    data
    text
    <p>Can you produce a Python example of how to download a Google Docs spreadsheet given its key and worksheet ID (<code>gid</code>)? I can't.</p> <p>I've scoured versions 1, 2 and 3 of the API. I'm having no luck, I can't figure out their compilcated ATOM-like feeds API, the <code>gdata.docs.service.DocsService._DownloadFile</code> private method says that I'm unauthorized, and I don't want to write an entire Google Login authentication system myself. I'm about to stab myself in the face due to frustration.</p> <p>I have a few spreadsheets and I want to access them like so:</p> <pre><code>username = 'mygooglelogin@gmail.com' password = getpass.getpass() def get_spreadsheet(key, gid=0): ... (help!) ... for row in get_spreadsheet('5a3c7f7dcee4b4f'): cell1, cell2, cell3 = row ... </code></pre> <p>Please save my face.</p> <hr> <p><strong>Update 1:</strong> I've tried the following, but no combination of <code>Download()</code> or <code>Export()</code> seems to work. (Docs for <code>DocsService</code> <a href="http://gdata-python-client.googlecode.com/svn/trunk/pydocs/gdata.docs.service.html" rel="noreferrer">here</a>)</p> <pre><code>import gdata.docs.service import getpass import os import tempfile import csv def get_csv(file_path): return csv.reader(file(file_path).readlines()) def get_spreadsheet(key, gid=0): gd_client = gdata.docs.service.DocsService() gd_client.email = 'xxxxxxxxx@gmail.com' gd_client.password = getpass.getpass() gd_client.ssl = False gd_client.source = "My Fancy Spreadsheet Downloader" gd_client.ProgrammaticLogin() file_path = tempfile.mktemp(suffix='.csv') uri = 'http://docs.google.com/feeds/documents/private/full/%s' % key try: entry = gd_client.GetDocumentListEntry(uri) # XXXX - The following dies with RequestError "Unauthorized" gd_client.Download(entry, file_path) return get_csv(file_path) finally: try: os.remove(file_path) except OSError: pass </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload