Google Docs API with Python

Using the Google Docs API, I am trying to create new docs and also provide a list of all current documents in a specific folder in my Google Docs. I start with python development, so I'm a little rough around the edges.

Things I'm trying to do:

  • Create a collection (or folder) named [Folder Name] ONLY if that name does not already exist
  • Create a document inside [Folder Name]
  • Only from [Folder Name] get a list of documents along with links to the documents themselves

I believe that I am using the Google Docs API 3.0 and using the gdata-2.0.16 helper for python.

Code so far:

    import gdata.docs.data
    import gdata.docs.client

    class SampleConfig (object):
        APP_NAME = 'GDataDocumentsListAPISample-v1.0'
        DEBUG = False

    client = gdata.docs.client.DocsClient ()
    client.ClientLogin ('[email_address]', '[password]', source = SampleConfig.APP_NAME)

    col = gdata.docs.data.Resource (type = 'folder', title = 'Folder Name')
    col = client.CreateResource (col)

    doc = gdata.docs.data.Resource (type = 'document', title = 'I did this')
    doc = client.CreateResource (doc, collection = col)

So, now to the questions: where am I hopelessly stuck:

  • How to check if [folder name] exists?
  • How to get contents ONLY [Folder Name]?
  • How can I get absolute links to all the documents that I create in this folder?

I know that I am far from complete here, but any help or advice you could give would be wonderful.

Thanks in advance!

+5
source share
1

. , , . Python:

# Create a query matching exactly a title, and include collections
q = gdata.docs.client.DocsQuery(
    title='EFD',
    title_exact='true',
    show_collections='true'
)

# Execute the query and get the first entry (if there are name clashes with
# other folders or files, you will have to handle this).
folder = client.GetResources(q=q).entry[0]

# Get the resources in the folder
contents = client.GetResources(uri=folder.content.src)

# Print out the title and the absolute link
for entry in contents.entry:
    print entry.title.text, entry.GetSelfLink().href

My posted doc https://docs.google.com/...
subtestcoll2 https://docs.google.com/...
guestimates_1 https://docs.google.com/...
phase 2 delivery plan - draft https://docs.google.com/...
Meeting agenda June 09 https://docs.google.com/...
Phase 2 spec for Graeme 2 March 2009 https://docs.google.com/...
EFD Meeting 2nd June https://docs.google.com/...
+3

All Articles