我正在与http://pygsheets.readthedocs.io/en/latest/index.html围绕谷歌工作表api v4封装。如何使用pygsheets上传工作表
我有一个小脚本,我试图选择一个json工作表上传到Google工作表。文件名是由在:
spreadsheetname_year_month_xxx.json
代码:
import tkinter as tk
import tkFileDialog
import pygsheets
root = tk.Tk()
root.withdraw()
file_path = tkFileDialog.askopenfilename()
print file_path
file_name = file_path.split('/')[-1]
print file_name
file_name_segments = file_name.split('_')
spreadsheet = file_name_segments[0]
worksheet = file_name_segments[1]+'_'+file_name_segments[2]
gc = pygsheets.authorize(outh_file='client_secret_xxxxxx.apps.googleusercontent.com.json')
ssheet = gc.open(spreadsheet)
ws = ssheet.add_worksheet(worksheet(ssheet,str(raw_input(file_path))))
文件路径导致生成的JSON文件看起来像:
{
"count": 12,
"results": [
{
"case": "abc1",
"case_name": "invalid",
"case_type": "invalid",
},
{
"case": "abc2",
"case_name": "invalid",
"case_type": "invalid",
},
............
我得到:
File "upload_to_google_sheets.py", line 27, in <module>
ws = ssheet.add_worksheet(worksheet(ssheet,str(raw_input(file_path))))
TypeError: 'unicode' object is not callable
正如你可以看到我试图用json数据实例化工作表。我究竟做错了什么?
你确定你做对了吗?因为jsonSheet参数包含工作表工作表的属性,因此应采用此格式https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#Sheet。你是否试图用json文档中的值更新工作表? – nithin