forked from AirPheonixSaksham/Hacker-Uploader
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp_bar.py
More file actions
118 lines (94 loc) · 3.35 KB
/
p_bar.py
File metadata and controls
118 lines (94 loc) · 3.35 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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 = 10
completed_length = int(current * bar_length / total)
remaining_length = bar_length - completed_length
progress_bar = "▰" * completed_length + "▱" * remaining_length
try:
uploadeing_text = (
f"📦 Upload Status \n\n"
f"📁 Upload Root\n"
f"├── 🐼 WELCOME: ᑌᑭᒪOᗩᗪᗴᖇ ACTIVE\n"
f"│ ├── 📊 Progress Bar: {progress_bar}\n"
f"│ ├── ⚡ Speed: {sp}\n"
f"│ ├── 🧭 Progress: {perc}\n"
f"│ ├── 🗂️ Loaded: {cur}\n"
f"│ ├── 🤏 Size: {tot}\n"
f"│ └── ⏳ ETA: {eta}\n"
f"└── 🚀 Bot By: SAKSHAM"
)
await reply.edit(uploadeing_text)
except FloodWait as e:
time.sleep(e.x)