T
T
TheMergus2019-08-03 13:23:35
Python
TheMergus, 2019-08-03 13:23:35

How to add a number to the database in a day?

There is a bot in the telegram and a database (SQLite)
The user performed an action (for example: wrote "Bonus" to the bot), 1 is taken away from the user in the database, how to make the user add 1 after 24 hours?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
tutuborg, 2019-08-03
@tutuborg

Add immediately. But! Together with the date-time from which the bonus begins to operate.
Then it will be easy to get the current value of the bonus in the request, depending on the current date-time. The entire calculation will be taken over by the DBMS engine.

D
Denioo, 2019-08-03
@Denioo

Elementary! add a check and that's it. Those. when a person enters a bonus, 1 is taken away from him, then when he has 0, and 24 hours have not passed since the last moment when he took the bonus, and he asks for a bonus - say, like, no time has passed.
In the database, I see it like this, there is a data column tied to a specific identifier (bonus) that is responsible for these points. And when a person takes a bonus in the data column and the identifier (bonus), his data is written, i.e. date and bonus are always overwritten. Why do you need to add 1 every 24? when you can check and that's it.

S
Sergey Sokolov, 2019-08-03
@sergiks

You can record user actions in the database with a timestamp. Then at any point in time, you can calculate the current number of points by "losing" the history of his actions.
When there is too much data and calculations become difficult, you can do snapshots: save an intermediate number of points in the database and then count from this moment, and not from the beginning of time.

M
Mike, 2019-08-03
@google_online

You can record the date in the database and then check whether the day has passed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question