我有一个小脚本,可以从 API 中获取数据并将其写入谷歌电子表格。这适用于 gspread。
我希望脚本每晚运行以检查新更新。
目前它看起来像这样
活动日期 - 活动地点 - 表演者 - 评论
问题是最后一行将手动插入,前 3 行将是从 json 文件提供的数据。
如果我在星期一晚上运行脚本并且日期如下
15/10/1 - comment for the 1st
15/10/2 - comment for the 2nd
15/10/10 - comment for the 10th
然后在 15/10/5 星期二添加,它将正确覆盖单元格,但评论将保留在手动添加的同一行上。像这样:
15/10/1 - comment for the 1st
15/10/2 - comment for the 2nd
15/10/5 - comment for the 10th
15/10/10 - no comment
即使在其中插入了一些新行,我如何确保相应的注释也向下移动。
数据只是被重写而不是下推。
def getActivity(query):
data = query.get_data("/events/event%3Aprofile%3A%22demo(c)%22%20event%3Adate%3A%23next365days%20(event%3Alocation%3Aconcertzaal%20%2B%20event%3Alocation%3Atheaterzaal%20%2B%20event%3Alocation%3Abalzaal%20%2B%20event%3Alocation%3Acafe)")
i=0
eventdata = {}
for w in data["data"]:
id=data["data"][i]["id"]
location = data['data'][i]['locations'][0]['name']
start = data['data'][i]['starttime']
artiest = data['data'][i]['name']
status = data['data'][i]['status']['name']
eventdata[start] = [lokatie, artiest, status]
i=i+1
return eventdata
def exportToSheet(query, worksheet, eventdata):
# worksheet.update_cell(5, 5, naam)
cellOffset = 2
for key in sorted(eventdata):
start = key
location = eventdata[key][0]
artiest = eventdata[key][1]
status = eventdata[key][2]
if location == "CONCERTZAAL":
worksheet.update_cell(cellOffset, 1, start)
worksheet.update_cell(cellOffset, 3, artiest)
worksheet.update_cell(cellOffset, 4, status)
cellOffset=cellOffset+1
if location == "BALZAAL":
worksheet.update_cell(cellOffset, 5, start)
worksheet.update_cell(cellOffset, 7, artiest)
worksheet.update_cell(cellOffset, 8, status)
cellOffset=cellOffset+1
if location == "THEATERZAAL":
worksheet.update_cell(cellOffset, 9, start)
worksheet.update_cell(cellOffset, 11, artiest)
worksheet.update_cell(cellOffset, 12, status)
cellOffset=cellOffset+1
worksheet.update_cell(1,1, "CONCERTZAAL")
worksheet.update_cell(1,2, "Opmerking")
worksheet.update_cell(1,3, "Artist")
worksheet.update_cell(1,4, "Status")
worksheet.update_cell(1,5, "BALZAAL")
worksheet.update_cell(1,6, "Opmerking")
worksheet.update_cell(1,7, "Artist")
worksheet.update_cell(1,8, "Status")
worksheet.update_cell(1,9, "THEATERZAAL")
worksheet.update_cell(1,10, "Opmerking")
worksheet.update_cell(1,11, "Artist")
worksheet.update_cell(1,12, "Status")
如果有帮助,这就是 excel 的样子: https ://i.gyazo.com/85a3b2de5a5fd3e2b1d0c7877b5d5921.png