A
A
AlmazKayum2020-07-23 23:01:59
Python
AlmazKayum, 2020-07-23 23:01:59

How to make an algorithm that executes a command at a specific time?

Good time.
There is the following task:

We accept hour values ​​from the user, for example, 10:30, 19:00. There may be one clock value, or there may be several. The user also specifies the time zone + 3 from UTC, for example,
it is necessary to send certain information to the user at the specified time. There can be many users.

While I understood that it is necessary to store time zones in a separate table in the database, as deviations from UTC in seconds, +3 is 3*60*60 = 10800 sec.
And store user IDs and deviations from 00:00 in seconds in a separate table, for example, for 10:30, it will be 10*60*60 + 30*60 = 37800 seconds.

What is the algorithm for launching a command to send information?

The simplest option, but also the most unreliable:
At 00:00 UTC, we launch the command in 10800 + 37800 = 48600 seconds.
That is, we start the function, where there is a pause of 48600 seconds and then the execution of the command. Any restart of the script or server will result in messages not being sent.

Who knows, tell me the algorithm in words, or some Python libraries. If it is unclear and difficult to explain - write questions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2020-07-23
@sergiks

Time should be stored in Unix time. We received a watch and his belt from the user, immediately transferred it to a timestamp, and saved an integer.
How to send. There are system mechanisms, such as cron in Linux. You can try to make your bike based on: in general, this is an endless loop that looks to see if it's time to do something "now".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question