async def periodic(sleep_for):
while True:
await sleep(sleep_for)
if db.mailing_state() == 'on':
logger.info('Сделали рассылку')
post = db.get_post(randint(0, len(db.get_keys_posts())))
for user_id in db.get_all_users():
try:
if post[2]:
await bot.send_photo(user_id, post[2], caption=post[1])
else:
await bot.send_message(user_id, post[1])
except Exception as _ex:
logger.info(f'Не удалось отправить сообщение пользователю - {user_id} Ошибка: {_ex}')
async def start_periodic():
await create_task(periodic(db.get_time()))
if __name__ == '__main__':
logger.info('Bot start!')
dp.run_polling(bot)
I need to make an interval mailing list. I already wrote a function that sends out messages to all db users, but I can't figure out how I can get it to work. Who can help?