S
S
sidorikv2020-09-22 06:53:11
Python
sidorikv, 2020-09-22 06:53:11

How can you do a time check in Python?

How can you implement time checking in Python?
I have js script:

function lg() {
    document.querySelector("#checkout > div.buttonContainer > button").click();
}

function doCheck() {
    const now = new Date();
    if (now.getHours() !== 13) { // часы
    timeout(5);
    } 
    else {
    if (now.getMinutes() !== 00) { // минуты
    timeout(5);
    } 
    else {
    if (now.getSeconds() !== 00) { // секунды
    timeout(5);
    } 
    else {
    setTimeout(lg, 1); // Задержка на выполнение скрипта в мс
    }
    }
    }
    }
    
function timeout(ms = 1) {
    setTimeout(() => {
    doCheck();
    }, ms);
    }
    
doCheck();


This script checks the PC for a given time and presses the button on the site at the right time. And how exactly the same script can be implemented in python? That is: So that at the right time python opens the link in the browser through selenium?
I.e. First, the browser is opened ( selenium ), then it is checked for a given time, a link is opened at the right time.
If someone can, please post the code! I will be extremely grateful

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kirillinyakin, 2020-09-22
@kirillinyakin

To do this, you can use task schedulers, in Linux it is cron, in windows it also seems to have its own task scheduler, and directly under Python there is something like Celery

L
LXSTVAYNE, 2020-09-29
@lxstvayne

schedule module .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question