1

I am taking data from a webpage that updates every morning that updates at different times and I would like to know how to get a script to run every 10 minutes or so to check if the website has been updated. I was thinking of somehow using cron but I don't understand it very well. Thanks for your help.

Ecoturtle
  • 445
  • 1
  • 4
  • 7

1 Answers1

1

Have you tried using the package APScheduler? It makes it fairly simple to schedule tasks. Here's the documentation.

To do a scheduled task, this is all that needs to be done (for something basic):

from apscheduler.schedulers.background import BackgroundScheduler
from pytz import utc

scheduler = BackgroundScheduler()
scheduler.configure(timezone=utc)

def print_hello():
    print("Hello, this is a scheduled event!")

job = scheduler.add_job(print_hello, 'interval', minutes=1, max_instances=10)
scheduler.start()

Note, however, that I had a small bug when I first tried to use the library, but an explanation of how to fix that is here.

Community
  • 1
  • 1
  • Hey, thanks for the solution. So if I run this once with a scheduled job, say everyday at 7am to 9am, every 10 mins do some thing, I only need to run the script once and it will continue to do this thing every day without me needing to have my computer on or running the script? – Ecoturtle Mar 30 '17 at 18:26
  • This simple implementation would not continue running after the computer shuts down, but the library does have tools to allow continuity in a script once the computer restarts. I would suggest diving deep into the documentation. – Bradley Robinson Mar 31 '17 at 13:43