From b8d5ec5465da4847058ecdaeb0b71c55c2ce00a8 Mon Sep 17 00:00:00 2001 From: taizan-hokouto <55448286+taizan-hokuto@users.noreply.github.com> Date: Mon, 26 Oct 2020 22:34:25 +0900 Subject: [PATCH] Remove unnecessary lines --- pytchat/core/pytchat.py | 8 ++++---- pytchat/core_async/livechat.py | 7 +++---- pytchat/core_multithread/livechat.py | 5 ++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pytchat/core/pytchat.py b/pytchat/core/pytchat.py index a1c9942..7ab76f6 100644 --- a/pytchat/core/pytchat.py +++ b/pytchat/core/pytchat.py @@ -4,7 +4,6 @@ import signal import time import traceback import urllib.parse -from threading import Event from ..parser.live import Parser from .. import config from .. import exceptions @@ -154,19 +153,20 @@ class PytchatCore: ''' continuation = urllib.parse.quote(continuation) livechat_json = None - status_code = 0 + err = None url = f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1" for _ in range(MAX_RETRY + 1): with client: try: livechat_json = client.get(url, headers=headers).json() break - except (json.JSONDecodeError, httpx.ConnectTimeout, httpx.ReadTimeout, httpx.ConnectError): + except (json.JSONDecodeError, httpx.ConnectTimeout, httpx.ReadTimeout, httpx.ConnectError) as e: + err = e time.sleep(2) continue else: self._logger.error(f"[{self._video_id}]" - f"Exceeded retry count. status_code={status_code}") + f"Exceeded retry count. Last error: {str(err)}") raise exceptions.RetryExceedMaxCount() return livechat_json diff --git a/pytchat/core_async/livechat.py b/pytchat/core_async/livechat.py index b7e3e44..8feb8df 100644 --- a/pytchat/core_async/livechat.py +++ b/pytchat/core_async/livechat.py @@ -191,7 +191,7 @@ class LiveChatAsync: self._logger.error(f"{traceback.format_exc(limit = -1)}") raise - self._logger.debug(f"[{self._video_id}]finished fetching chat.") + self._logger.debug(f"[{self._video_id}] finished fetching chat.") raise exceptions.ChatDataFinished async def _check_pause(self, continuation): @@ -243,7 +243,6 @@ class LiveChatAsync: ''' continuation = urllib.parse.quote(continuation) livechat_json = None - status_code = 0 url = f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1" for _ in range(MAX_RETRY + 1): try: @@ -255,7 +254,7 @@ class LiveChatAsync: continue else: self._logger.error(f"[{self._video_id}]" - f"Exceeded retry count. status_code={status_code}") + f"Exceeded retry count.") return None return livechat_json @@ -318,7 +317,7 @@ class LiveChatAsync: try: self._task_finished() except CancelledError: - self._logger.debug(f'[{self._video_id}]cancelled:{sender}') + self._logger.debug(f'[{self._video_id}] cancelled:{sender}') def terminate(self): if self._pauser.empty(): diff --git a/pytchat/core_multithread/livechat.py b/pytchat/core_multithread/livechat.py index 70cff01..eb49086 100644 --- a/pytchat/core_multithread/livechat.py +++ b/pytchat/core_multithread/livechat.py @@ -183,7 +183,7 @@ class LiveChat: self._logger.error(f"{traceback.format_exc(limit=-1)}") raise - self._logger.debug(f"[{self._video_id}]finished fetching chat.") + self._logger.debug(f"[{self._video_id}] finished fetching chat.") raise exceptions.ChatDataFinished def _check_pause(self, continuation): @@ -235,7 +235,6 @@ class LiveChat: ''' continuation = urllib.parse.quote(continuation) livechat_json = None - status_code = 0 url = f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1" for _ in range(MAX_RETRY + 1): with client: @@ -247,7 +246,7 @@ class LiveChat: continue else: self._logger.error(f"[{self._video_id}]" - f"Exceeded retry count. status_code={status_code}") + f"Exceeded retry count.") raise exceptions.RetryExceedMaxCount() return livechat_json