Python Remote Trigger Scripts at variable User Selected Times

Поделиться
HTML-код
  • Опубликовано: 18 окт 2024
  • 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.
    So I looked at some method with a HTML file that would use something like JavaScript that would start python.exe then run a python 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.
    I wanted a Pythonic solution so I needed to use either Django or Flask app to be able to start python.exe then run a python script.
    I looked at a number of methods to do this and in the end followed Gyan Of Python's Python Flask Application On IIS | Deploy Flask Application On IIS: • Python Flask Applicati...
    He has a repository of github with some scripts : github.com/may... to help you create IIS site that will run the flaskapp to do this.
    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 (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.
    I hope this is of help to you, if so, can you please give a thumbs up for the video. Muchas Gracias Please visit my blog for similar topics: cr8ive.tk
    Kind regards, Max Drake

Комментарии •