我正在制作一个脚本,用于从 Google 表单检查 Google 工作表,并将结果作为民意调查的实时反馈可视化结果返回。我需要弄清楚如何更新值计数,但仅限于更新 google 工作表时,而不是每 60 秒(或其他)检查一次。
这是我当前的设置:
string = ""
while True:
responses = gc.open("QOTD Responses").sheet1
data = pd.DataFrame(responses.get_all_records())
vals = data['Response'].value_counts()
str = "{} currently has {} votes. \n{} currently has {} votes.".format(vals.index[0], vals[0], vals.index[1],
vals[1])
if(str != string):
string = str
print(string)
time.sleep(60) # Updates 1440 times per day
我几乎可以肯定一定有更好的方法来做到这一点,但是那会是什么?
谢谢!
最佳答案
您无法单独使用 Python 来完成此任务。您需要与 trigger function from Google Apps script 集成.
您可以使用 onEdit 触发函数向 Python 脚本发送信号(例如通过 http 调用)。
To use a simple trigger, simply create a function that uses one of these reserved function names:
onOpen(e) runs when a user opens a spreadsheet, document, presentation, or form that the user has permission to edit.
onEdit(e) runs when a user changes a value in a spreadsheet.
关于Python GSpead 变化监听器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52721158/