Make application that runs until a certain time in python

1

I am trying to make a web spyder that obtains information from the web. The problem is that normally when the program meets its objectives and stops working, however the pages from which I get information are being updated continuously so I want my program to run continuously without stopping from one time to another. For example, from 3 in the morning to 6 in the afternoon.

I do not know how to program this so that the application runs continuously so I would appreciate any kind of help.

Greetings and thanks in advance!

    
asked by Albert 26.12.2016 в 20:29
source

4 answers

1

I do not know what operating system you are working on in Linux and derivatives you can put an entry in the crontab. Example:

15 10 * * * usuario /home/usuario/scripts/actualizar.sh

The update.sh script will run every day at 10 with 15 min.

On windows in a scheduled task.

Greetings.

    
answered by 26.12.2016 в 21:38
1

I think the solution comes with datetime:

from datetime import datetime
from datetime import time
hora_inicio = time(3,0,0) # tres de la mañana
hora_finalizacion = time(6,0,0) # seis de la mañana
while True:
    actual = datetime.now()
    actual = time(actual.hour, actual.minute,actual.second)  # este objeto se puede comparar sin tener en cuenta la fecha
    if actual > hora_inicio and actual < hora_finalizacion:
        web_spider()
    else:
        break
    
answered by 26.12.2016 в 23:53
0

I do not know in detail your implementation, but it could be something like that

import time

while true:
    web_spider()
    time.sleep(intervalo_de_tiempo_en_segundos)

You can review in more detail how to work with the method time here

    
answered by 26.12.2016 в 20:48
0

I think this is the simplest thing I would do.

from datetime import time

start_time = time(3, 0, 0)
end_time = time(6, 0, 0)
while datetime.time.now() > start_time and datetime.time.now() < end_time:
    llama_funcion()

I hope I have helped.

    
answered by 25.01.2017 в 11:39