-2

I am creating an automation script using pyautogui to click on a specific href text 'Start'. This text moves to the next section on the same page after 2 hours. Is there a module which can be used to tell the current time and if the time is in the specified interval then run a function like def(func1), if the condition satisfied for second interval then run def(func2)

  • 1
    If you are on Linux Crontab may be a better bet, on Windows task scheduler. You can set these up to run your script however you want. – kabanus Jul 13 '20 at 05:09
  • Is there a search engine looking for answer to basic questions before asking it again for the 100th time? [ask] – Julien Jul 13 '20 at 05:09
  • In Python, use [datetime](https://stackoverflow.com/questions/415511/how-to-get-the-current-time-in-python). – kabanus Jul 13 '20 at 05:10
  • @kabanus Windows task scheduler is for running the script at a specified time sure. But what I need is that if I run the script it will check the time and run a specific function which is satisfied by for the specific time interval. – Amrit Anand Jul 13 '20 at 05:18

1 Answers1

0

One way is to just store the current time from time.time() in a variable, make a while loop and check if the difference between time.time() and that variable is greater than the time you want to wait for.

import time
start_time = time.time()

while (start_time - time.time() < time_in_seconds_to_wait):
    pass

# rest of the code that gets executed after the wait
Julien
  • 13,986
  • 5
  • 29
  • 53
S. Strempfer
  • 290
  • 2
  • 6
  • I'm sorry if that's against some rule, I just wanted to stress that it might be better to look into some sort of task scheduler since it is a pretty long (sorry opinion) timeout. – S. Strempfer Jul 13 '20 at 05:45
  • You are welcome to propose your favorite approach, I'm just pointing out that self qualifying it as the 'best' or 'easiest' or whatever other subjective superlative, especially in bold as if this cannot even be questioned, is unnecessary... We try to keep away from opinions and concentrate on facts. :) – Julien Jul 13 '20 at 05:53