forked from mohitbooraget/New_Txt_Random
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Easy_F.py
45 lines (35 loc) · 34.1 KB
/
Easy_F.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
from datetime import datetime,timedelta
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])