From 4b4f2889190753f4e9ea9d4158b0407299f38c52 Mon Sep 17 00:00:00 2001 From: Dantenerosas Date: Wed, 18 Oct 2023 00:15:44 +0300 Subject: [PATCH] wip telegram test --- src/core/master_service.py | 4 +++- .../Telegram/telegram_media_downloader/telegram_parser.py | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/master_service.py b/src/core/master_service.py index e6657d0..e892754 100644 --- a/src/core/master_service.py +++ b/src/core/master_service.py @@ -81,7 +81,9 @@ class MasterService: app.pre_run() app.is_running = True tg_client.start() - result = downloader.video_download(client=tg_client) + loop = asyncio.get_running_loop() + asyncio.set_event_loop(loop) + loop.run_until_complete(downloader.video_download(client=tg_client)) return result case _: result = downloader.video_download() diff --git a/src/parsers/Telegram/telegram_media_downloader/telegram_parser.py b/src/parsers/Telegram/telegram_media_downloader/telegram_parser.py index 1b18d43..74bd92e 100644 --- a/src/parsers/Telegram/telegram_media_downloader/telegram_parser.py +++ b/src/parsers/Telegram/telegram_media_downloader/telegram_parser.py @@ -51,7 +51,7 @@ def asyncio_gather(*futures, return_exceptions=False) -> list: class TelegramParser(BaseParser): - def video_download(self, client: Client = None): + async def video_download(self, client: Client = None): url_parse_result = urlparse(self.params["link"]) channel, message_id = url_parse_result.path[1:].split('/') if "/c/" not in url_parse_result.path else \ url_parse_result.path[3:].split('/') @@ -68,8 +68,8 @@ class TelegramParser(BaseParser): mode="w+", encoding="utf-8") as f: YAML().dump(config, f) if _check_config(): - a = asyncio_run(download_all_chat(client)) - b = asyncio_run(worker(client)) + await download_all_chat(client) + await worker(client) client.stop() app.is_running = False logger.info("Stopped!")