[英]Trigger Python script on local machine from Website
I have a WordPress site running on an external server, I also have a local machine running a Python script. 我有一个在外部服务器上运行的WordPress网站,也有一个运行Python脚本的本地计算机。
I am looking for a way to trigger the python script from the WordPress install. 我正在寻找一种从WordPress安装触发python脚本的方法。
I know I can use the publish_post hook in WordPress to activate whenever a new post is published but I am unsure of the best way to link that to my local machine. 我知道我可以在发布新帖子时使用WordPress中的publish_post钩子来激活它,但是我不确定将其链接到本地计算机的最佳方法。
Anyone have an example of something similar being done? 有人举过类似的例子吗? Would the WordPress Rest API be of any use here?
WordPress Rest API在这里有用吗?
The only safe way I can think of is to "poll" the website from the local machine. 我能想到的唯一安全的方法是从本地计算机“轮询”网站。 It is impractical and insecure to access the local machine from the website.
从网站访问本地计算机是不切实际和不安全的。
You need to find a condition that changes and can be examined using the local script and use that to determine whether to take the necessary action or not. 您需要找到一个可以更改的条件,并且可以使用本地脚本进行检查,并使用该条件来确定是否采取必要的措施。 This could be another PHP script on the WordPress site giving you state information, or just a web call locally.
这可能是WordPress网站上的另一个PHP脚本,可以为您提供状态信息,也可以只是本地的网络调用。
WordPress wouldn't have access to your python script. WordPress无法访问您的python脚本。 But you python script has access to WordPress.
但是您的python脚本可以访问WordPress。 It should periodically fetch the data from the WordPress installation URL / Blog page.
它应该定期从WordPress安装URL /博客页面获取数据。 And this will have to be scheduled periodically like every 4 hours if that's how frequently the posts are published.
而且,如果发布的频率如此高,则必须像每4个小时一样定期进行安排。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.