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 = []