Skip to content

Instantly share code, notes, and snippets.

@olivergeorge
Created December 1, 2010 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivergeorge/722969 to your computer and use it in GitHub Desktop.
Save olivergeorge/722969 to your computer and use it in GitHub Desktop.
Download documents from Google Docs in doc, html, zip and pdf format. Note: zip=html+images
import gdata.docs.data
import gdata.docs.client
import re
def print_feed(feed):
if not feed.entry:
print 'No entries in feed.'
for entry in feed.entry:
print entry.title.text.encode('UTF-8'), entry.GetDocumentType(), entry.resource_id.text
for folder in entry.InFolders():
print folder.title
def download(resourceId, filename="file"):
entry = client.GetDoc(resourceId)
for ext in ('doc', 'zip', 'html', 'pdf'):
print ext, "..."
client.Export(entry, "%s.%s" % (filename, ext))
def safe_title(title):
return re.sub(r'[^a-zA-Z_-]', '', title)
def download_folder(folder_uid):
feed = client.GetDocList(uri='/feeds/default/private/full/%s/contents' % (folder_uid))
for entry in feed.entry:
title=entry.title.text.encode("UTF-8")
document_id = entry.resource_id.text
print "Downloading", title
download(document_id, safe_title(title))
client = gdata.docs.client.DocsClient(source='xxx-download-v1')
client.ssl = True
client.http_client.debug = False
client.ClientLogin('xxx@gmail.com', 'XXXX', client.source)
# Get all top level folders
# feed = client.GetDocList(uri='/feeds/default/private/full?showfolders=true')
# Get list of files in a folder
# feed = client.GetDocList(uri='/feeds/default/private/full/folder:0B5w0mnT5s6eINmRiYWE4YWYtOGUwZC00MTJkLWFlZjktMDJjMzE2YThjNjMx/contents')
# print_feed(feed)
test_folder_uid = "folder:0B5w0mnT5s6eINmRiYWE4YWYtOGUwZC00MTJkLWFlZjktMDJjMzE2YThjNjMx"
test_document_uid = "document:1hDGJyEUUFtMpe32zsXWMGNsTUic6HVoBI9gLjqlHq0M"
download_folder(test_folder_uid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment