From aec5deb32c37c6c39eb3fd788d4f0c7c6dd59565 Mon Sep 17 00:00:00 2001 From: k0te1ch Date: Sat, 15 Aug 2026 17:38:06 +0300 Subject: [PATCH] refactor(bot): drop dead HTTP_methods module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit None of get_my_ip/downloadFile/download_file is referenced anywhere in the repo — the module name doesn't appear outside the file itself. Downloads go through the aiogram bot session and the dialog engine now. It also held the only asyncio.CancelledError handler that swallowed cancellation into a False return, plus four print() calls. --- app/bot/utils/HTTP_methods.py | 71 ----------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 app/bot/utils/HTTP_methods.py diff --git a/app/bot/utils/HTTP_methods.py b/app/bot/utils/HTTP_methods.py deleted file mode 100644 index 165b04e..0000000 --- a/app/bot/utils/HTTP_methods.py +++ /dev/null @@ -1,71 +0,0 @@ -import asyncio - -import aiofiles -import aiohttp -from loguru import logger - -from main import bot - - -@logger.catch -async def get_my_ip() -> str: - """ - Getting the bot's IP address - :return: str - """ - session = await bot.get_session() - async with session.get("https://ipinfo.io/json") as r: - jdata = await r.json() - logger.opt(colors=True).debug("Get IP") - return jdata.get("ip") - - -@logger.catch -async def downloadFile(url: str, filename: str, chunk_size: int = 65536) -> None: - """ - Deleting a message - :param: url - :param: filename - :param: chunk_size = 65536 - :return: None - """ - logger.opt(colors=True).debug(f"The file started downloading ({filename})") - session = await bot.get_session() - async with session.get( - url, - raise_for_status=True, - ) as response: - f = open(filename, "wb") - while True: - chunk = await response.content.read(chunk_size) - if not chunk: - break - f.write(chunk) - f.flush() - f.close() - logger.opt(colors=True).debug(f"File downloaded ({filename})") - - -async def download_file(url, destination): - try: - async with aiohttp.ClientSession() as session, session.get(url) as response: - if response.status == 200: - async with aiofiles.open(destination, "wb") as f: - while True: - chunk = await response.content.read(1024) - if not chunk: - break - await f.write(chunk) - return True - else: - print(f"Error downloading file, status code: {response.status}") - return False - except aiohttp.ClientError as e: - print(f"Aiohttp client error: {e}") - return False - except asyncio.CancelledError: - print("Download was cancelled") - return False - except Exception as e: - print(f"Error downloading file: {e}") - return False