4

I am working on web crawler app to download the stock price every ten minutes. I am able to extract the quote but I am not sure how to schedule it to run every ten minutes for the entire day. Please suggest me either time loop kind of a thing or the solution for the web crawler app itself.
I need a solution which works on Windows.

ElmoVanKielmo
  • 10,907
  • 2
  • 32
  • 46
Shiva Prakash
  • 1,849
  • 4
  • 21
  • 25

4 Answers4

6

Ok, so you have a python function f() which you want to execute every ten mins for a day. You can do this:

import time
while True: #Infinite loop
    f() #Execute the function
    time.sleep(600) #Wait 600s (10 min) before re-entering the cycle

And you keep the script running for as long as you need (a day, a week, whatever, it will not close by itself)

francisco sollima
  • 7,952
  • 4
  • 22
  • 38
1

you can do try this

import time

and but this code before dawnload method

time.sleep(10*60) #this will stop the program for 10 minutes
1

Use crontab. Open the crontab file via terminal:

$ crontab -e

At the end of the file you can set the python script and the frequency of running it. For example to run a script every 10 mins:

*/10 * * * * /path/to/script
1

Windows has a Task Scheduler built-in. You can use that to run your script:

Otherwise, you can write an infinite loop that will check the stock prices every ten minutes using something like time.sleep(600). Note that you can add your program to run at startup fairly easily:

Community
  • 1
  • 1
Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88