skip to Main Content

Right now, I have a python script which uses an API to make calls to my shopify website, getting all the orders. It’s a really simple script and basically uses an imported module to make these calls.

I need to run this script daily, and so I looked to the Google App Engine to do this. However, all the tutorials for Python refer to using Django or Flask. All I want to do is run a simple script daily that makes the API calls – no UI or anything. I’ve already researched their cron and have a basic idea of how it works, but I’m stumped on how to get the actual script to run.

If someone could quickly explain how I can go about this, it would be much appreciated.

Thanks in advance!

3

Answers


  1. Hello you could use Flask to run the script for you automatically daily without adding a UI just create your basic Flask application that will run the script for you something like this:

    from flask import Flask
    app = Flask(__name__)
    
    @app.route("/")
    #define your script here as a view function or create a view function and
    # and call your script from that view 
    if __name__ == "__main__":
        app.run()
    

    I hope that helps you

    Login or Signup to reply.
  2. Why don’t you go for cron in linux or task scheduler for windows?

    Both run script at specified time, make sure you set timezone properly and give a trial run before scheduling the main job 🙂
    This gives an insight on setting up cron —- https://www.howtogeek.com/101288/how-to-schedule-tasks-on-linux-an-introduction-to-crontab-files/

    You have to type sudo crontab -e, enter as a privileged user and use nano editor(I prefer) to remove hashtags and type in your command, one line= one command for cron.

    Rest, the tutorial is pretty self explanatory.

    Login or Signup to reply.
  3. Create a cron.yaml in the same folder as app.yaml

    add to cron.yaml

    cron:
    - description: "description of task"
      url: path to file (similar to http request)
      schedule: every 24 hours
    

    deploy cron.yaml using
    gcloud app deploy cron.yaml

    usual deployment using ‘gcloud app deploy’ does not include cron.yaml. You have to do it separately using the above command.

    after deploying cron.yaml, check for the cron job on console (app engine->task queues -> cron jobs)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search