Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AlgorithmAlchemy/7612925ff69bc9474562ae8e22a067d6 to your computer and use it in GitHub Desktop.
Save AlgorithmAlchemy/7612925ff69bc9474562ae8e22a067d6 to your computer and use it in GitHub Desktop.
AIOGRAM 2.X... progress bar
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}")
@AlgorithmAlchemy
Copy link
Author

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'\rProgress: [{bar}] {percentage:.2f}%', end='', flush=True)

def simulate_process(total_time):
    for t in range(total_time + 1):
        progress_bar(t, total_time)
        time.sleep(1)

total_time = 20
simulate_process(total_time)
print()  # Добавляем новую строку после завершения прогресса

@AlgorithmAlchemy
Copy link
Author

`
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