Answer the question
In order to leave comments, you need to log in
How to loop an increase in a number?
Bot on aiogram. The number 10 is stored in the database. I need this number to increase by 10 every hour.
I get this number:
@dp.message_handler(commands=['number'])
async def number(message: types.Message):
conn = sqlite3.connect('db.db')
cur = conn.cursor()
user_id = message.from_user.id
result = cur.execute("SELECT * FROM table WHERE user_id = ?", (user_id, )).fetchone()
number = result[4]
await message.reply(f'{number}')
number1 = 10
cur.execute("UPDATE table SET number = number + ? WHERE user_id = ?", (number1, user_id))
conn.commit()
Answer the question
In order to leave comments, you need to log in
I will answer the question with a question: why do you need to increase the number every hour, if you can instead remember when this number was last changed? Then, when you need a number, you simply count how many hours have passed since then, and how many should be now. It is easier to implement and more economical in terms of resources.
And then the cycle for all users, and even periodically ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question