forked from UsergeTeam/Userge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Udith <[email protected]>
- Loading branch information
Showing
3 changed files
with
88 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
#!/bin/bash | ||
|
||
python3 -m userge |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,60 @@ | ||
import math | ||
from pyrogram import Message | ||
from pyrogram.errors.exceptions import FloodWait | ||
import time | ||
from .tools import humanbytes, time_formatter | ||
|
||
|
||
async def progress(current, | ||
total, | ||
ud_type, | ||
message, | ||
start): | ||
async def progress( | ||
current, | ||
total, | ||
ud_type, | ||
message: Message, | ||
start | ||
): | ||
now = time.time() | ||
diff = now - start | ||
if diff % 10 < 0.05 or current == total: | ||
percentage = current * 100 // total | ||
speed = current // diff | ||
time_to_completion = (total - current) // speed | ||
time_to_completion = time_formatter(seconds=time_to_completion) | ||
progress_str = "Progress :: {}%\n".format(int(percentage)) | ||
out = progress_str + "{0} of {1}\nSpeed: {2}/s\nETA: {3}\n".format( | ||
humanbytes(current), | ||
humanbytes(total), | ||
humanbytes(speed), | ||
time_to_completion if time_to_completion != '' else "0 s" | ||
) | ||
text = "{}\n{}".format( | ||
ud_type, | ||
out | ||
) | ||
if message.text != text: | ||
try: | ||
await message.edit(text) | ||
except FloodWait: | ||
pass | ||
|
||
if round(diff % 10.00) == 0 or current == total: | ||
# if round(current / total * 100, 0) % 5 == 0: | ||
percentage = current * 100 / total | ||
speed = current / diff | ||
elapsed_time = round(diff) * 1000 | ||
time_to_completion = round((total - current) / speed) * 1000 | ||
estimated_total_time = elapsed_time + time_to_completion | ||
|
||
elapsed_time = await time_formatter(milliseconds=elapsed_time) | ||
estimated_total_time = await time_formatter(milliseconds=estimated_total_time) | ||
|
||
progress = "[{0}{1}] \nP: {2}%\n".format( | ||
''.join(["█" for i in range(math.floor(percentage / 5))]), | ||
''.join(["░" for i in range(20 - math.floor(percentage / 5))]), | ||
round(percentage, 2)) | ||
def humanbytes(size): | ||
# https://stackoverflow.com/a/49361727/4723940 | ||
# 2**10 = 1024 | ||
if not size: | ||
return "" | ||
power = 1024 | ||
n = 0 | ||
Dic_powerN = {0: ' ', 1: 'Ki', 2: 'Mi', 3: 'Gi', 4: 'Ti'} | ||
while size > power: | ||
size /= power | ||
n += 1 | ||
return "{:.2f} {}B".format(size, Dic_powerN[n]) | ||
|
||
tmp = progress + "{0} of {1}\nSpeed: {2}/s\nETA: {3}\n".format( | ||
await humanbytes(current), | ||
await humanbytes(total), | ||
await humanbytes(speed), | ||
# elapsed_time if elapsed_time != '' else "0 s", | ||
estimated_total_time if estimated_total_time != '' else "0 s" | ||
) | ||
|
||
try: | ||
await message.edit("{}\n {}".format(ud_type, tmp)) | ||
|
||
except: | ||
pass | ||
def time_formatter(seconds: int) -> str: | ||
minutes, seconds = divmod(int(seconds), 60) | ||
hours, minutes = divmod(minutes, 60) | ||
days, hours = divmod(hours, 24) | ||
tmp = ((str(days) + "d, ") if days else "") + \ | ||
((str(hours) + "h, ") if hours else "") + \ | ||
((str(minutes) + "m, ") if minutes else "") + \ | ||
((str(seconds) + "s, ") if seconds else "") | ||
return tmp[:-2] |