-1

everyone. Hope someone can help me.

I have an API connection and I want to request/get and store (atualize my csv where the data is located) data hourly without using task scheduler from Windows. Basically I want to schedule the python file to run at 6am, 7am, 8am, 9 and so on.

Do you know how I can do that?

  • You can run an infinite loop every minute. And run your code if conditions are met. – sifat Sep 19 '22 at 17:08
  • Does this answer your question? [Scheduling Python Script to run every hour accurately](https://stackoverflow.com/questions/22715086/scheduling-python-script-to-run-every-hour-accurately) – ThePyGuy Sep 19 '22 at 17:11

2 Answers2

0

There is a python module that does exactly that: https://schedule.readthedocs.io/en/stable/

But please be aware of this chapter: https://schedule.readthedocs.io/en/stable/#when-not-to-use-schedule.

Florin C.
  • 593
  • 4
  • 13
0

One option is to do it with Rocketry:

from rocketry import Rocketry
from rocketry.conds import daily

app = Rocketry()

@app.task(daily.at("06:00") | daily.at("07:00") | daily.at("08:00") | daily.at("09:00"))
def process_data():
    ... # Do the task

if __name__ == "__main__":
    app.run()

But that gets tedious, it seems you want it to run hourly between certain time which can be also achieved by:

from rocketry import Rocketry
from rocketry.conds import hourly, time_of_day

app = Rocketry()

@app.task(hourly & time_of_day.between("06:00", "09:00"))
def process_data():
    ... # Do the task

if __name__ == "__main__":
    app.run()

Note: | is OR operator and & is AND operator. The first argument in the .task is a condition that is either True or False (if True, the task will start).

miksus
  • 2,426
  • 1
  • 18
  • 34