From a32d9d422f750f561f62e2c72f818db2f2cc253f Mon Sep 17 00:00:00 2001 From: Capybara-z Date: Thu, 20 Feb 2025 20:07:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=20=D0=B1=D0=B0=D0=B9=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Добавлен конвертатор байтов. --- handlers/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/handlers/utils.py b/handlers/utils.py index ec5cd57a..264692ed 100644 --- a/handlers/utils.py +++ b/handlers/utils.py @@ -206,3 +206,19 @@ async def edit_or_send_message( reply_markup=reply_markup, disable_web_page_preview=disable_web_page_preview, ) + +def convert_to_bytes(value: float, unit: str) -> int: + """ + Конвертирует значение с указанной единицей измерения в байты. + Args: + value (float): Числовое значение. + unit (str): Единица измерения ('KB', 'MB', 'GB', 'TB'). + Returns: + int: Количество байт. + """ + KB = 1024 + MB = KB * 1024 + GB = MB * 1024 + TB = GB * 1024 + units = {"KB": KB, "MB": MB, "GB": GB, "TB": TB} + return int(value * units.get(unit.upper(), 1))