From 8c7fc2780d5d59b6f75a4f01afb0f32793aaa742 Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 24 Nov 2020 23:17:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E8=85=BE=E8=AE=AF=E7=BF=BB?= =?UTF-8?q?=E8=AF=91=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/translate.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/models/translate.py b/models/translate.py index a2e0264..a59ffb4 100644 --- a/models/translate.py +++ b/models/translate.py @@ -135,7 +135,19 @@ class TencentTranslate(TranslateProvider): async def _do_init(self): try: - async with _http_session.post('https://fanyi.qq.com/api/reaauth') as r: + async with _http_session.get('https://fanyi.qq.com/') as r: + if r.status != 200: + logger.warning('TencentTranslate init request failed: status=%d %s', r.status, r.reason) + return False + html = await r.text() + + m = re.search(r"""\breauthuri\s*=\s*['"](.+?)['"]""", html) + if m is None: + logger.exception('TencentTranslate init failed: reauthuri not found') + return False + reauthuri = m[1] + + async with _http_session.post('https://fanyi.qq.com/api/' + reauthuri) as r: if r.status != 200: logger.warning('TencentTranslate init request failed: status=%d %s', r.status, r.reason) return False @@ -160,9 +172,9 @@ class TencentTranslate(TranslateProvider): async def _reinit_coroutine(self): try: while True: - await asyncio.sleep(55 * 60) + await asyncio.sleep(30) while True: - logger.info('TencentTranslate reinit') + logger.debug('TencentTranslate reinit') try: if await self._do_init(): break