Skip to content

Instantly share code, notes, and snippets.

@hiroshineya
Created May 17, 2012 06:23
Show Gist options
  • Select an option

  • Save hiroshineya/2716964 to your computer and use it in GitHub Desktop.

Select an option

Save hiroshineya/2716964 to your computer and use it in GitHub Desktop.
retrieve file list from GoogleDocs
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import datetime
import os
import os.path
import time
import atom
import gdata.docs
import gdata.docs.service
import gdata.docs.client
import gdata.docs.data
import gdata.data
import gdata.client
# Google Docsのファイル一覧取得
def list_file(c):
i = 0
for entry in c.GetDocumentListFeed().entry:
i = i + 1
print "%02d : file [%s][%s]" % (i, entry.title.text.decode('utf-8'), entry.GetDocumentType())
# Google Docsのディレクトリ一覧取得
def list_dir(c):
i = 0
q = gdata.docs.service.DocumentQuery(categories=['folder'], params={'showfolders': 'true'})
for entry in c.Query(q.ToUri()).entry:
i = i + 1
print "%02d : dir [%s]" % (i, entry.title.text.decode('utf-8'))
def main():
res = 0
retrieve_client = gdata.docs.service.DocsService()
try:
user_id = sys.argv[1]
passwd = sys.argv[2]
retrieve_client.ClientLogin(user_id, passwd)
print "login done.."
# these needs DocsService
list_file(retrieve_client)
list_dir(retrieve_client)
except gdata.client.BadAuthentication:
print "login error...."
res = 9
except:
print "Unexpected error:", sys.exc_info()[0]
res = 9
return res
if __name__ == "__main__":
print "start"
res = main()
if res != 0:
print "ERROE END !!"
sys.exit(res)
print "process done.."
sys.exit(0)
@hiroshineya

Copy link
Copy Markdown
Author

prototype..
retrieve file list from GoogleDocs

need
gdata-python-client:
http://code.google.com/p/gdata-python-client/

https://developers.google.com/google-apps/documents-list/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment