I an wondering is there is a way to write to google spreadsheet using Python. Found python-gdata-client library, installed it with all dependencies. Using this code below but it is not working
import time
import gdata.spreadsheet.service
email = '[email protected]'
password = 'pwd'
weight = '180'
# Find this value in the url with 'key=XXX' and copy XXX below
spreadsheet_key = 'pRoiw3us3wh1FyEip46wYtW'
# All spreadsheets have worksheets. I think worksheet #1 by default always
# has a value of 'od6'
worksheet_id = 'Sheet1'
spr_client = gdata.spreadsheet.service.SpreadsheetsService()
spr_client.email = email
spr_client.password = password
spr_client.source = 'Example Spreadsheet Writing Application'
spr_client.ProgrammaticLogin()
# Prepare the dictionary to write
dict = {}
dict['date'] = time.strftime('%m/%d/%Y')
dict['time'] = time.strftime('%H:%M:%S')
dict['weight'] = weight
print dict
entry = spr_client.InsertRow(dict, spreadsheet_key, worksheet_id)
if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
print "Insert row succeeded."
else:
print "Insert row failed."
This is the error is says -
Traceback (most recent call last):
File "D:/steve/test.py", line 28, in <module>
entry = spr_client.InsertRow(dict, spreadsheet_key, worksheet_id)
File "C:\Python27\lib\site-packages\gdata\spreadsheet\service.py", line 338, in InsertRow
converter=gdata.spreadsheet.SpreadsheetsListFromString)
File "C:\Python27\lib\site-packages\gdata\service.py", line 1235, in Post
media_source=media_source, converter=converter)
File "C:\Python27\lib\site-packages\gdata\service.py", line 1346, in PostOrPut
redirects_remaining - 1, media_source, converter=converter)
File "C:\Python27\lib\site-packages\gdata\service.py", line 1328, in PostOrPut
return converter(result_body)
File "C:\Python27\lib\site-packages\gdata\spreadsheet\__init__.py", line 376, in SpreadsheetsListFromString
xml_string)
File "C:\Python27\lib\site-packages\atom\__init__.py", line 92, in optional_warn_function
return f(*args, **kwargs)
File "C:\Python27\lib\site-packages\atom\__init__.py", line 126, in CreateClassFromXMLString
tree = ElementTree.fromstring(xml_string)
File "<string>", line 124, in XML
ParseError: mismatched tag: line 944, column 4