From 0dfe1d8b7e5db136337a5b7477739c45ba8e8e81 Mon Sep 17 00:00:00 2001 From: jsdio Date: Tue, 4 Jul 2023 15:10:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B1=D0=BA=D0=B8=20=D0=BD=D0=B5=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83?= =?UTF-8?q?=D0=B7=D0=BA=D0=B8=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B8?= =?UTF-8?q?=D0=B7=20getnativeiblockelementslist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extractor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/extractor.py b/src/extractor.py index ca11c0d..1bfd31b 100644 --- a/src/extractor.py +++ b/src/extractor.py @@ -30,7 +30,11 @@ class ApiExtractor: async with aiohttp.ClientSession() as session: async with session.get(url=url, headers=self.headers, data=data) as resp: - return json.loads(await resp.text()) + try: + return json.loads(await resp.text()) + except json.JSONDecodeError: + logging.error(f'Получены неверные данные - {resp.text()}') + return {} @backoff.on_exception(backoff.expo, (aiohttp.ClientResponseError, aiohttp.ClientConnectorError, aiohttp.ServerDisconnectedError), base=2, factor=1, @@ -45,8 +49,10 @@ class ApiExtractor: data['fields'] = json.dumps(self.fields + fields, ensure_ascii=False) else: data['fields'] = json.dumps(self.fields + ["PROPERTY_*"], ensure_ascii=False) - min_id = state.get_state(f'iblock_{iblock_id}') or os.getenv('LAST_ID') or 0 + if os.getenv('LAST_ID').isdigit(): + if int(min_id) < int(os.getenv('LAST_ID')): + min_id = os.getenv('LAST_ID') data['bitrFilter'] = json.dumps({'>ID': str(min_id)}, ensure_ascii=False) abitrs = []