【问题标题】:Python GSpead On-Change Listener?Python GSpead 更改监听器?
【发布时间】:2018-10-09 12:31:54
【问题描述】:

我正在制作一个脚本,用于检查来自谷歌表单的谷歌表格并将结果作为投票的实时供稿可视化返回。我需要弄清楚如何更新值计数,但只有在更新谷歌表时,而不是每 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 python-3.x gspread


    【解决方案1】:

    您将无法仅使用 Python 完成此操作。您需要与trigger function from Google Apps script 集成。

    您可以使用 onEdit 触发器函数向您的 python 脚本发送信号(例如通过 http 调用)。

    要使用简单的触发器,只需创建一个函数,该函数使用以下之一 这些保留的函数名:

    • onOpen(e) 在用户打开电子表格、文档、 用户有权编辑的演示文稿或表单。

    • onEdit(e) 在用户更改电子表格中的值时运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      • 2010-09-08
      • 2011-07-16
      相关资源
      最近更新 更多