キーとワークシートID()を指定してGoogle Docsスプレッドシートをダウンロードする方法のPythonの例を作成できますgid
か?私はできません。
APIのバージョン1、2、3を精査しました。私は運が悪く、コンパイルされたATOMのようなフィードAPIを理解できません。gdata.docs.service.DocsService._DownloadFile
プライベートメソッドは私が無許可であると言っており、Googleログイン認証システム全体を自分で作成したくありません。欲求不満で顔を刺そうとしています。
スプレッドシートがいくつかあり、次のようにアクセスしたいと思います。
username = 'mygooglelogin@gmail.com'
password = getpass.getpass()
def get_spreadsheet(key, gid=0):
... (help!) ...
for row in get_spreadsheet('5a3c7f7dcee4b4f'):
cell1, cell2, cell3 = row
...
私の顔を救ってください。
更新1:次のことを試しましたが、組み合わせがないDownload()
か、機能していないExport()
ようです。DocsService
(ここのドキュメント)
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