python - 检查公共 Google 表格是否/何时被修改
问题描述
我正在使用一个非常简单的 python 脚本来使用库拉入一个 Google 表格(我没有写入权限)requests
,并写出一个 csv 文件,将标题修改为我的 CMS(Wordpress)需要的内容更新一些数据。
我不想重新导出文件,除非它是自上次运行脚本以来修改的 Google 表格。
看起来使用Python Google API库是一种选择,但可能超出了此任务的必要性。
GSpread包看起来很有希望,但是该属性
worksheet.updated
(看起来早在 2015 年就会包含一个日期时间字符串)目前似乎不起作用
这个 :
>>> 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 的副本,并将任何新导入与创建新导出文件之前的导入进行比较。也许这是一个足够简单的解决方案,因为它只有几百行数据。
有什么建议吗?
解决方案
推荐阅读
- java - Java运行自定义groovy代码,如何保证groovy安全?
- android - 如何在 android manifest 中按顺序设置启动画面和其他活动?
- c++ - 在 Windows 中禁用便携式设备
- blockchain - 错误 3080006:EOSIO 区块链中的交易时间过长
- c# - 为什么 C# 中的局部变量必须在初始化后初始化并在 If 运算符条件中强制转换?
- symfony4 - php -S 127.0.0.1:8000 -t public 不起作用
- javascript - 如何在网站中实现 Postman 任务
- javascript - VueJS 组件数据未更新
- amazon-web-services - 如何从 Glacier 存储类过渡到 Deep Archive 存储类?
- reactjs - 当 CSS 模块不在同一个 CSS 文件中时,如何通过 CSS 模块识别相同的类名