首页 > 解决方案 > 检查公共 Google 表格是否/何时被修改

问题描述

我正在使用一个非常简单的 python 脚本来使用库拉入一个 Google 表格(我没有写入权限)requests,并写出一个 csv 文件,将标题修改为我的 CMS(Wordpress)需要的内容更新一些数据。

我不想重新导出文件,除非它是自上次运行脚本以来修改的 Google 表格。

这个 :

>>> import gspread
>>> from oauth2client.service_account import ServiceAccountCredentials
>>> scope = ['https://spreadsheets.google.com/feeds'] 
>>> creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
>>> client = gspread.authorize(creds)
>>> file_id = '1rYQ84SIKTFUOTl1xyFkHMNLt9CW3tOMFbOelOvVwx1k'
>>> url = "https://docs.google.com/spreadsheets/d/{0}".format(file_id)
>>> doc = client.open_by_url(url)
>>> sheet = doc.get_worksheet(0)
>>> sheet.updated
>>> 

我最初的想法是保存未修改的导入 csv 的副本,并将任何新导入与创建新导出文件之前的导入进行比较。也许这是一个足够简单的解决方案,因为它只有几百行数据。

有什么建议吗?

标签: pythonpython-3.xgoogle-sheetsgspread

解决方案


推荐阅读