如何在googledocs电子表格更改时点击URL

2024-04-18 07:42:10 发布

您现在位置:Python中文网/ 问答频道 /正文

当Google电子表格文档被保存或修改时,我们如何才能点击URL/服务呢。例如,假设我有一个关于googledocs的电子表格示例。我想在每次更改电子表格时点击一个URL。我们如何在Python中做到这一点?如有任何帮助,我们将不胜感激。在

谢谢


Tags: 文档url示例google电子表格googledocs
1条回答
网友
1楼 · 发布于 2024-04-18 07:42:10

我刚刚写了一个脚本,它报告文档的创建/编辑时间。当看到更改时,您应该能够调整它以命中URL(或执行任何操作)。在

https://gist.github.com/1646532下面的代码

# Stuart Powers
# report when any google docs are created or changed


import os
import sys
import simplejson
import gdata.docs.service


"""
This script will report which google docs have been modified or created since
it was last run.

It compares the timestamps retrieved from google with the timestamps from the
JSON file which is updated each time the script is called.  It compares each
document's last-updated timestamp against what they were the previous time the
script was ran, it does this by using a 'docs.json' to save state.

Inspired by the stackoverflow question:
    "How to hit a URL when Google docs spreadsheet is changed"
    http://stackoverflow.com/questions/8927164/

"""


docs = gdata.docs.service.DocsService()
docs.ClientLogin('stuart.powers@gmail.com','xxxxxxxx')



# create a dictionary of doc_id/timestamp key/values
mydict = {}
for e in docs.GetDocumentListFeed().entry:
    mydict[e.id.text] = e.updated.text


# if docs.json doesn't exist, create it with our dict's data and then exit
# because there's nothing to compare against
if not os.path.exists('docs.json'):
    with open('docs.json','w') as o:
        o.write(simplejson.JSONEncoder().encode(mydict))
    sys.exit(0)


# otherwise, load the previous data from docs.json
last_data = simplejson.load(open('docs.json'))

# and compare the timestamps
for id in mydict.keys():
    if id not in last_data:
        print 'new: %s' % id
    if mydict[id] != last_data[id]:
        print 'changed: %s' % id


# update docs.json for next time and then quit
with open('docs.json','w') as o:
    o.write(simplejson.JSONEncoder().encode(mydict))

相关问题 更多 >