mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2025-12-29 09:44:50 +00:00
* ci: Update .deepsource.toml
* ci: Update .deepsource.toml
* style: format code with black and isort
Format code with black and isort
This commit fixes the style issues introduced in 0fb651a according to the output
from Black and isort.
Details: https://app.deepsource.com/gh/yasirarism/MissKatyPyro/transform/d8f2f66e-b496-4686-aca6-9830236eda12/
---------
Co-authored-by: deepsource-io[bot] <42547082+deepsource-io[bot]@users.noreply.github.com>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
SIZE_UNITS = ["B", "KB", "MB", "GB", "TB", "PB"]
|
|
|
|
|
|
def get_readable_file_size(size_in_bytes) -> str:
|
|
if size_in_bytes is None:
|
|
return "0B"
|
|
index = 0
|
|
while size_in_bytes >= 1024:
|
|
size_in_bytes /= 1024
|
|
index += 1
|
|
try:
|
|
return f"{round(size_in_bytes, 2)}{SIZE_UNITS[index]}"
|
|
except IndexError:
|
|
return "File too large"
|
|
|
|
|
|
def get_readable_time(seconds: int) -> str:
|
|
result = ""
|
|
(days, remainder) = divmod(seconds, 86400)
|
|
days = int(days)
|
|
if days != 0:
|
|
result += f"{days}d "
|
|
(hours, remainder) = divmod(remainder, 3600)
|
|
hours = int(hours)
|
|
if hours != 0:
|
|
result += f"{hours}h "
|
|
(minutes, seconds) = divmod(remainder, 60)
|
|
minutes = int(minutes)
|
|
if minutes != 0:
|
|
result += f"{minutes}m "
|
|
seconds = int(seconds)
|
|
result += f"{seconds}s "
|
|
return result
|
|
|
|
|
|
def get_readable_bitrate(bitrate_kbps):
|
|
return (
|
|
f"{str(round(bitrate_kbps / 1000, 2))} Mb/s"
|
|
if bitrate_kbps > 10000
|
|
else f"{str(round(bitrate_kbps, 2))} kb/s"
|
|
)
|
|
|
|
|
|
def get_readable_time2(seconds: int) -> str:
|
|
count = 0
|
|
ping_time = ""
|
|
time_list = []
|
|
time_suffix_list = ["s", "m", "h", "d", "w", "m", "y"]
|
|
while count < 4:
|
|
count += 1
|
|
remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24)
|
|
if seconds == 0 and remainder == 0:
|
|
break
|
|
time_list.append(int(result))
|
|
seconds = int(remainder)
|
|
for i in range(len(time_list)):
|
|
time_list[i] = str(time_list[i]) + time_suffix_list[i]
|
|
if len(time_list) == 4:
|
|
ping_time += f"{time_list.pop()}, "
|
|
time_list.reverse()
|
|
ping_time += ":".join(time_list)
|
|
return ping_time
|