forked from mohitbooraget/New_Txt_Random
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p_bar.py
103 lines (82 loc) · 3.13 KB
/
p_bar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import time
import math
import os
from pyrogram.errors import FloodWait
class Timer:
def __init__(self, time_between=5):
self.start_time = time.time()
self.time_between = time_between
def can_send(self):
if time.time() > (self.start_time + self.time_between):
self.start_time = time.time()
return True
return False
from datetime import datetime,timedelta
#lets do calculations
def hrb(value, digits= 2, delim= "", postfix=""):
"""Return a human-readable file size.
"""
if value is None:
return None
chosen_unit = "B"
for unit in ("KiB", "MiB", "GiB", "TiB"):
if value > 1000:
value /= 1024
chosen_unit = unit
else:
break
return f"{value:.{digits}f}" + delim + chosen_unit + postfix
def hrt(seconds, precision = 0):
"""Return a human-readable time delta as a string.
"""
pieces = []
value = timedelta(seconds=seconds)
if value.days:
pieces.append(f"{value.days}d")
seconds = value.seconds
if seconds >= 3600:
hours = int(seconds / 3600)
pieces.append(f"{hours}h")
seconds -= hours * 3600
if seconds >= 60:
minutes = int(seconds / 60)
pieces.append(f"{minutes}m")
seconds -= minutes * 60
if seconds > 0 or not pieces:
pieces.append(f"{seconds}s")
if not precision:
return "".join(pieces)
return "".join(pieces[:precision])
timer = Timer()
# designed by Mendax
async def progress_bar(current, total, reply, start):
if timer.can_send():
now = time.time()
diff = now - start
if diff < 1:
return
else:
perc = f"{current * 100 / total:.1f}%"
elapsed_time = round(diff)
speed = current / elapsed_time
remaining_bytes = total - current
if speed > 0:
eta_seconds = remaining_bytes / speed
eta = hrt(eta_seconds, precision=1)
else:
eta = "-"
sp = str(hrb(speed)) + "/s"
tot = hrb(total)
cur = hrb(current)
#don't even change anything till here
# Calculate progress bar dots
#ab mila dil ko sukun #by AirPheonix
#change from here if you want
bar_length = 11
completed_length = int(current * bar_length / total)
remaining_length = bar_length - completed_length
progress_bar = "▓" * completed_length + "▒" * remaining_length
try:
await reply.edit(f'╭──⌈📤 𝙐𝙥𝙡𝙤𝙖𝙙𝙞𝙣𝙜 📤⌋──╮ \n├{progress_bar}\n├ 𝙎𝙥𝙚𝙚𝙙✴️ : {sp} \n├ 𝙋𝙧𝙤𝙜𝙧𝙚𝙨𝙨🕓 : {perc} \n├ 𝙇𝙤𝙖𝙙𝙚𝙙📁 : {cur}\n├ 𝙎𝙞𝙯𝙚📚 : {tot} \n├ 𝙀𝙏𝘼⏳: {eta} \n╰────⌈ 𝔸𝔻𝕀𝕋𝕐𝔸⚡ ⌋───╯\n')
except FloodWait as e:
time.sleep(e.x)