Python GSpead 变化监听器?

标签 python python-3.x gspread

我正在制作一个脚本,用于从 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/

相关文章:

python - GSpread 导入错误 : No module named oauth2client. service_account

Python:从具有最大长度的子列表中返回前 n 个列表

python - 在 Python 中循环工作时无法变得简单

Python Selenium 找到输入元素但无法发送键

python - 为多列绘制 seaborn catplots

python - 为什么Python斐波那契序列循环比递归慢?

python - 使用 Pytest 和 conftest.py 文件时未显示断言错误的预期结果

python - Django Python 与 Gspread : 'choices' must be an iterable containing (actual value, 人类可读名称)元组

python - Google Sheets API :"Invalid JSON payload received. Unknown name "编号“位于 'data.values[0]' : Cannot find field

python - Pandas 读取 csv 并在引用中转义引用