filmov
tv
Python Remote Trigger Scripts at variable User Selected Times

Показать описание
You can use Task Scheduler to trigger Python Scripts on Remote server at specified times, either hourly, daily or at some other predictable interval. This is fine for scripts that are gathering data from say an API and pushing it up into a DB on a regular basis.
But what do you do if you want to trigger an API for something more volatile? Like weather for the next hour or current share prices for your specific portfolio, in the middle of the day or say at 4pm?
How do you allow for triggering these scripts? If you are at a PC you could connect into Remote Server and run the Task Scheduler at that specific time, but what if you are out and about and only have your mobile phone?
I initially looked at a sort of PowerShell or Command Propt process that would allow you to run a .BAT file on your local PC that would then open a connection to a Remote Server and run a BAT file on the Server. I did not find a satisfactory solution using that method.
So thought about a Button on a Web page. You pressed the button and it would activate a script on the server and activate the script.
Initially Bing Crosby (aka Bing Chat) gave me a JavasCript process using :
require('child_process').spawn()'
But I found that method relied on having Nodfe.JS running on your server.
The only difference from his code to mine is I also added the flask-cors library as well to make it work.
I initially tried to install a Flask App in an Existing Website sub-folder and run this remotely.
It wouldn’t run and I got a Mixed Block error on the Developer Screen with the Network view , as the Flask App was running as http & the Html file on the remote PC browser was a HTTPS:// so there was a conflict between the Https (secure ) and the http (not secure) and it was blocked.
Itried running a http:// (unsecured) from remote pc browser and it would just TIME OUT and would not work.
Creating a Site for the Flask app (as per tutorial above) allowed me to make a HTTP:// site (using IP address of server) and that wouldn’t work (blocked ) so I had to add a security certificate ( already created for my sites using LetEncrypt) and make it an HTTPS:// site, then it worked.
I got an error when trying to open the URL because I used a certificate from another site, but once I told it to accept the certificate I could then access the scripts remotely.
Kind regards, Max Drake
But what do you do if you want to trigger an API for something more volatile? Like weather for the next hour or current share prices for your specific portfolio, in the middle of the day or say at 4pm?
How do you allow for triggering these scripts? If you are at a PC you could connect into Remote Server and run the Task Scheduler at that specific time, but what if you are out and about and only have your mobile phone?
I initially looked at a sort of PowerShell or Command Propt process that would allow you to run a .BAT file on your local PC that would then open a connection to a Remote Server and run a BAT file on the Server. I did not find a satisfactory solution using that method.
So thought about a Button on a Web page. You pressed the button and it would activate a script on the server and activate the script.
Initially Bing Crosby (aka Bing Chat) gave me a JavasCript process using :
require('child_process').spawn()'
But I found that method relied on having Nodfe.JS running on your server.
The only difference from his code to mine is I also added the flask-cors library as well to make it work.
I initially tried to install a Flask App in an Existing Website sub-folder and run this remotely.
It wouldn’t run and I got a Mixed Block error on the Developer Screen with the Network view , as the Flask App was running as http & the Html file on the remote PC browser was a HTTPS:// so there was a conflict between the Https (secure ) and the http (not secure) and it was blocked.
Itried running a http:// (unsecured) from remote pc browser and it would just TIME OUT and would not work.
Creating a Site for the Flask app (as per tutorial above) allowed me to make a HTTP:// site (using IP address of server) and that wouldn’t work (blocked ) so I had to add a security certificate ( already created for my sites using LetEncrypt) and make it an HTTPS:// site, then it worked.
I got an error when trying to open the URL because I used a certificate from another site, but once I told it to accept the certificate I could then access the scripts remotely.
Kind regards, Max Drake