Remove unnecessary lines

This commit is contained in:
taizan-hokouto
2020-10-26 22:34:25 +09:00
parent 3200c5654f
commit b8d5ec5465
3 changed files with 9 additions and 11 deletions

View File

@@ -4,7 +4,6 @@ import signal
import time import time
import traceback import traceback
import urllib.parse import urllib.parse
from threading import Event
from ..parser.live import Parser from ..parser.live import Parser
from .. import config from .. import config
from .. import exceptions from .. import exceptions
@@ -154,19 +153,20 @@ class PytchatCore:
''' '''
continuation = urllib.parse.quote(continuation) continuation = urllib.parse.quote(continuation)
livechat_json = None livechat_json = None
status_code = 0 err = None
url = f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1" url = f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1"
for _ in range(MAX_RETRY + 1): for _ in range(MAX_RETRY + 1):
with client: with client:
try: try:
livechat_json = client.get(url, headers=headers).json() livechat_json = client.get(url, headers=headers).json()
break 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) time.sleep(2)
continue continue
else: else:
self._logger.error(f"[{self._video_id}]" 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() raise exceptions.RetryExceedMaxCount()
return livechat_json return livechat_json

View File

@@ -191,7 +191,7 @@ class LiveChatAsync:
self._logger.error(f"{traceback.format_exc(limit = -1)}") self._logger.error(f"{traceback.format_exc(limit = -1)}")
raise raise
self._logger.debug(f"[{self._video_id}]finished fetching chat.") self._logger.debug(f"[{self._video_id}] finished fetching chat.")
raise exceptions.ChatDataFinished raise exceptions.ChatDataFinished
async def _check_pause(self, continuation): async def _check_pause(self, continuation):
@@ -243,7 +243,6 @@ class LiveChatAsync:
''' '''
continuation = urllib.parse.quote(continuation) continuation = urllib.parse.quote(continuation)
livechat_json = None livechat_json = None
status_code = 0
url = f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1" url = f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1"
for _ in range(MAX_RETRY + 1): for _ in range(MAX_RETRY + 1):
try: try:
@@ -255,7 +254,7 @@ class LiveChatAsync:
continue continue
else: else:
self._logger.error(f"[{self._video_id}]" self._logger.error(f"[{self._video_id}]"
f"Exceeded retry count. status_code={status_code}") f"Exceeded retry count.")
return None return None
return livechat_json return livechat_json
@@ -318,7 +317,7 @@ class LiveChatAsync:
try: try:
self._task_finished() self._task_finished()
except CancelledError: except CancelledError:
self._logger.debug(f'[{self._video_id}]cancelled:{sender}') self._logger.debug(f'[{self._video_id}] cancelled:{sender}')
def terminate(self): def terminate(self):
if self._pauser.empty(): if self._pauser.empty():

View File

@@ -183,7 +183,7 @@ class LiveChat:
self._logger.error(f"{traceback.format_exc(limit=-1)}") self._logger.error(f"{traceback.format_exc(limit=-1)}")
raise raise
self._logger.debug(f"[{self._video_id}]finished fetching chat.") self._logger.debug(f"[{self._video_id}] finished fetching chat.")
raise exceptions.ChatDataFinished raise exceptions.ChatDataFinished
def _check_pause(self, continuation): def _check_pause(self, continuation):
@@ -235,7 +235,6 @@ class LiveChat:
''' '''
continuation = urllib.parse.quote(continuation) continuation = urllib.parse.quote(continuation)
livechat_json = None livechat_json = None
status_code = 0
url = f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1" url = f"https://www.youtube.com/{self._fetch_url}{continuation}&pbj=1"
for _ in range(MAX_RETRY + 1): for _ in range(MAX_RETRY + 1):
with client: with client:
@@ -247,7 +246,7 @@ class LiveChat:
continue continue
else: else:
self._logger.error(f"[{self._video_id}]" self._logger.error(f"[{self._video_id}]"
f"Exceeded retry count. status_code={status_code}") f"Exceeded retry count.")
raise exceptions.RetryExceedMaxCount() raise exceptions.RetryExceedMaxCount()
return livechat_json return livechat_json