简体   繁体   English

从Google Apps脚本运行python脚本

[英]Running python script from Google Apps script

I have a python script (on my local machine) that queries Postgres database and updates a Google sheet via sheets API. 我有一个python脚本(在我的本地计算机上),该脚本查询Postgres数据库并通过工作表API更新Google工作表。 I want the python script to run on opening the sheet. 我希望python脚本在打开工作表时运行。 I am aware of Google Apps Script, but not quite sure how can I use it, to achieve what I want. 我知道Google Apps脚本,但不确定如何使用它来实现所需的功能。

Thanks 谢谢

Google Apps脚本在服务器端运行,因此不能用于运行本地脚本。

you will need several changes. 您将需要进行一些更改。 first you need to move the script to the cloud (see google compute engine) and be able to access your databases from there. 首先,您需要将脚本移动到云中(请参阅Google计算引擎),并能够从那里访问数据库。

then, from apps script look at the onOpen trigger. 然后,从应用脚本中查看onOpen触发器。 from there you can urlFetchApp to your python server to start the work. 从那里,您可以urlFetchApp到您的python服务器开始工作。

you could also add a custom "refresh" menu to the sheet to call your server which is nicer than having to reload the sheet. 您还可以在工作表中添加自定义的“刷新”菜单来调用服务器,这比重新加载工作表更好。

note that onOpen runs server side on google thus its impossible for it to access your local machine files. 请注意,onOpen在Google上运行服务器端,因此它无法访问本地计算机文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM