Created
March 4, 2024 15:54
-
-
Save AlgorithmAlchemy/7612925ff69bc9474562ae8e22a067d6 to your computer and use it in GitHub Desktop.
AIOGRAM 2.X... progress bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def update_progress(chat_id): | |
message = await bot.send_message(chat_id, "Генерация в процессе...\n0% [ ]") | |
try: | |
for i in range(1, 11): | |
progress = i * 10 | |
# Отображаем серые блоки | |
gray_blocks = '▒' * i + '░' * (10 - i) | |
await bot.edit_message_text(f"Генерация в процессе...\n{progress}% [{gray_blocks}]", chat_id, message.message_id) | |
await asyncio.sleep(0.5) # Даем время для отображения серых блоков | |
# Отображаем новый блок | |
new_block = '▓' | |
new_blocks = new_block + '▓' * (i - 1) + '░' * (10 - i) | |
await bot.edit_message_text(f"Генерация в процессе...\n{progress}% [{new_blocks}]", chat_id, message.message_id) | |
await asyncio.sleep(0.5) | |
# Отправляем сообщение "Успех!" и ждем 5 секунд | |
await bot.edit_message_text("Успех!", chat_id, message.message_id) | |
await asyncio.sleep(5) | |
# Удаляем сообщение через 10 секунд | |
await asyncio.sleep(10) | |
await bot.delete_message(chat_id, message.message_id) | |
except Exception as e: | |
print(f"Ошибка при обновлении прогресса: {e}") |
Author
AlgorithmAlchemy
commented
Jul 11, 2025
`
import time
def progress_bar(progress, total, bar_length=40):
filled_length = int(bar_length * progress // total)
bar = '█' * filled_length + '-' * (bar_length - filled_length)
percentage = progress / total * 100
print(f'Progress: [{bar}] {percentage:.2f}%')
def simulate_process(total_time):
for t in range(total_time + 1):`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment