D
D
DeeDD112021-12-31 15:30:26
Python
DeeDD11, 2021-12-31 15:30:26

How to add coins to the balance every 24 hours?

It is necessary that every 24 hours users are added 5 coins.

The code:

balance = int(5)
            db.addBalance(message.from_user.id, balance5)

def addBalance(self, user_id, balance):
        with self.connection:
            return self.cursor.execute("UPDATE `users` SET `balance` = ? WHERE `user_id` = ?", (balance, user_id,))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2021-12-31
@rPman

It is clear that the author did not bother to simply understand the code that he brought himself, it is necessary to correct the sql query in it

UPDATE `users` SET `balance` = `balance` + ? WHERE `user_id` = ?

And set up a periodic call to the addBalance method
... but this is a simple and wrong practice in building financial applications.
The fact is that financial applications should make it possible to analyze history (for example, so that you can make an analytical report for a period), and it is also necessary to identify and solve problems with logic and code, cancel transactions (and this is one of the ways to solve many others with external reasons), etc.
Therefore, all transactions should be stored in the database, and the final balance should be considered triggers based on this data (I just don’t recommend counting the sum of all transactions as a trigger each time, you need to store the balance, the update date and summarize new transactions with it)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question