From b380875582f6cd11e46f9043f5a424a23fdea775 Mon Sep 17 00:00:00 2001 From: Ilya Sapunov Date: Wed, 12 Mar 2025 18:03:04 +0300 Subject: [PATCH] Updated docs, updated modules, removed old methods --- .vscode/settings.json | 3 + docs/focus-compliance.rst | 16 +++-- docs/focus.rst | 6 +- docs/index.rst | 5 +- kontur_focus/__init__.py | 6 +- kontur_focus/focus.py | 36 +++++----- kontur_focus/focus_compliance.py | 62 +++++++++++++++++ kontur_focus/government_lists.py | 112 ------------------------------- kontur_focus/req.py | 10 ++- 9 files changed, 105 insertions(+), 151 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 kontur_focus/government_lists.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7e68766 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python-envs.pythonProjects": [] +} \ No newline at end of file diff --git a/docs/focus-compliance.rst b/docs/focus-compliance.rst index f80f044..f30078d 100644 --- a/docs/focus-compliance.rst +++ b/docs/focus-compliance.rst @@ -1,6 +1,6 @@ -========================== -Библиотека Фокус.Комплаенс -========================== +=============== +Фокус.Комплаенс +=============== Подготовка ---------- @@ -19,12 +19,16 @@ .. code-block:: python - from kontur_focus import Focus + from kontur_focus import FocusCompliance - focus = Focus(inn='', ogrn='') + fc = FocusCompliance(inn='', ogrn='') Обязательный параметр - **ИНН**. Основные методы ---------------- \ No newline at end of file +--------------- + +.. autofunction:: kontur_focus.FocusCompliance.company_is_foreign_agent() + +.. autofunction:: kontur_focus.FocusCompliance.person_is_foreign_agent() diff --git a/docs/focus.rst b/docs/focus.rst index 5e6b231..fd71a27 100644 --- a/docs/focus.rst +++ b/docs/focus.rst @@ -1,6 +1,6 @@ -================ -Библиотека Фокус -================ +===== +Фокус +===== Подготовка ---------- diff --git a/docs/index.rst b/docs/index.rst index 85ccd53..c3f09e4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -6,10 +6,7 @@ Kontur Focus Library documentation ================================== -Add your content using ``reStructuredText`` syntax. See the -`reStructuredText `_ -documentation for details. - +Библиотека-обертка для взаимодействия с REST API Контур.Фокус и Фокус.Комплаенс. .. toctree:: :maxdepth: 2 diff --git a/kontur_focus/__init__.py b/kontur_focus/__init__.py index 9f41461..5669ac7 100644 --- a/kontur_focus/__init__.py +++ b/kontur_focus/__init__.py @@ -1,5 +1,5 @@ -from .focus import Focus from .req import Request -from .government_lists import gl +from .focus import Focus +from .focus_compliance import FocusCompliance -__all__ = [Focus, Request, gl] +__all__ = [Request, Focus, FocusCompliance] diff --git a/kontur_focus/focus.py b/kontur_focus/focus.py index 2fe6a14..8e7a514 100644 --- a/kontur_focus/focus.py +++ b/kontur_focus/focus.py @@ -1,7 +1,5 @@ -import requests import os from dotenv import load_dotenv -from kontur_focus.government_lists import gl from kontur_focus.req import Request @@ -73,26 +71,22 @@ class Focus(Request): """ return self.get('/foreignRepresentatives') - def full_analytics(self): # DEPRECATED - return self.get('/analytics') + def government_lists(self): + """Вхождение организации в государственные реестры - @staticmethod - def government_lists(): - formatted_list = [(elem.get('name'), elem.get('description')) for elem in gl] - - return formatted_list - - def check_if_in_lists(self, list_name: str = None): + :return: Список реестров + :rtype: _type_ """ - Check if organization is consist in Government lists + response = self.get('/analyticLists') + + return response['listsEntries'] + + def is_foreign_agent(self): + """Проверка наличия организации в Едином реестре иностранных агентов - :param list_name: str List name - :return: json + :return: Результат проверки + :rtype: bool """ - if not list_name: - return self.get('/analyticLists') - else: - data = self.get('/analyticLists')[0]['listsEntries'] - list_id = next(item['uid'] for item in gl if item['name'] == list_name) - - return next(lst['isInList'] for lst in data if lst['id'] == list_id) + foreign_agents_list = next(lst for lst in self.government_lists() if lst['id'] == 'fcfc856d-89f8-408b-afef-56750cb90fed') + + return foreign_agents_list['isInList'] diff --git a/kontur_focus/focus_compliance.py b/kontur_focus/focus_compliance.py index e69de29..f0002fa 100644 --- a/kontur_focus/focus_compliance.py +++ b/kontur_focus/focus_compliance.py @@ -0,0 +1,62 @@ +from kontur_focus.req import Request +from dotenv import load_dotenv +import os + + +class FocusCompliance(Request): + _basedir = os.path.abspath(os.path.dirname(__file__)) + _focus_base_url = None + + def __init__(self, inn: str, ogrn: str = None): + load_dotenv() + super().__init__( + base_url=os.environ.get('FOCUS_COMPLIANCE_BASE_URL'), + api_key=os.environ.get('FOCUS_COMPLIANCE_ACCESS_KEY'), + inn=inn, + ogrn=ogrn + ) + self._focus_base_url = f'/banks/{os.environ.get('FOCUS_COMPLIANCE_BANK_ID')}' + + # Компании + def company_is_foreign_agent(self): + """Вхождение организации и ее руководителей в список иностранных агентов + + :return: Дата формирования реестра, а также признаки присутствия или отсутствия в списках иностранных агентов + :rtype: dict + """ + response = self.get(path=f'{self._focus_base_url}/companies/lists') + foreign_agent_list = response['foreignAgentList'] + company_in_list = [] + persons_in_company_in_list = [] + + for item in foreign_agent_list['uls']: + if item['listItemStatus'] == 'NotInList': + continue + else: + company_in_list.append(item) + + for person in foreign_agent_list['fls']: + if person['listItemStatus'] == 'NotInList': + continue + else: + persons_in_company_in_list.append(person) + + fal_data = { + 'list_date': str(foreign_agent_list['actualListDate']).split('T')[0], + 'company_in_list': True if company_in_list else False, + 'persons_in_company_in_list': True if persons_in_company_in_list else False + } + + return fal_data + + # Физлица + def person_is_foreign_agent(self): + """Вхождение физлица в список иностранных агентов + + :return: True или False + :rtype: bool + """ + response = self.get(path=f'{self._focus_base_url}/individuals') + fa = response[0]['foreignAgents'] + + return True if fa else False diff --git a/kontur_focus/government_lists.py b/kontur_focus/government_lists.py deleted file mode 100644 index 107d67e..0000000 --- a/kontur_focus/government_lists.py +++ /dev/null @@ -1,112 +0,0 @@ -gl = [ - { - 'name': 'illicit_reward', - 'uid': '53a2d6b8-2ca3-41a6-b3c2-f942d58b35fd', - 'description': 'Участники закупок, привлечённые к административной ответственности по ст. 19.28 КоАП РФ' - }, - { - 'name': 'banks', - 'uid': '7c1c310a-9c26-4e08-80f5-8b7611f28460', - 'description': 'Перечень кредитных организаций' - }, - { - 'name': 'insurance_business', - 'uid': 'c18dd28d-0028-4bad-b73c-c15de023d843', - 'description': 'Страховые компании' - }, - { - 'name': 'foreign_agents', - 'uid': 'fcfc856d-89f8-408b-afef-56750cb90fed', - 'description': 'Иностранные агенты' - }, - { - 'name': 'golden_share', - 'uid': 'd103af01-bf6d-470a-9eea-1536b840c287', - 'description': 'Золотая акция государства' - }, - { - 'name': 'msp_support', - 'uid': 'f0efa959-854f-4617-b24a-0f5dc7d8e28a', - 'description': 'Инфраструктура поддержки МСП' - }, - { - 'name': 'construction_sro_excluded', - 'uid': 'c318de8e-95b0-4b8e-bb13-1d65e43aa471', - 'description': 'Исключенные из реестра СРО в области строительства' - }, - { - 'name': 'design_sro_excluded', - 'uid': 'fa890998-6c87-40a5-9aee-ef547056a07f', - 'description': 'Исключённые из СРО в области изысканий и (или) проектирования' - }, - { - 'name': 'major_taxpayers', - 'uid': '91f7e831-cb59-47ae-b86a-c662ada337da', - 'description': 'Крупнейшие налогоплательщики' - }, - { - 'name': 'nko_public', - 'uid': '937e8c0c-c7da-42ff-b8ca-2a526a33e48b', - 'description': 'НКО - исполнители общественно полезных услуг Минюста России' - }, - { - 'name': 'pyramid_scheme', - 'uid': 'cd5b5b63-9cae-4ac5-b74f-d58b8066e696', - 'description': 'Признаки финансовой пирамиды' - }, - { - 'name': 'illegal_lender', - 'uid': '2227c3f1-934d-4d1f-8d08-a542518bfad9', - 'description': 'Признаки нелегального кредитора' - }, - { - 'name': 'illegal_brokers', - 'uid': 'b22b4c23-e02d-4819-8a7a-f32ca4185bc2', - 'description': 'Признаки нелегального профессионального участника рынка ценных бумаг' - }, - { - 'name': 'timber_transactions', - 'uid': 'bead481d-d201-4283-be29-5011621925b1', - 'description': 'Продавцы из реестра Сделки с древесиной' - }, - { - 'name': 'tour_operators', - 'uid': 'da30f33a-7034-4a4a-8869-4a4e523ec85d', - 'description': 'Реестр туроператоров' - }, - { - 'name': 'brokers', - 'uid': '04cec8e4-b375-4bbd-b0ff-6ef6d201da93', - 'description': 'Список брокеров' - }, - { - 'name': 'strategic_enterprises', - 'uid': 'd764d2a2-b33b-446f-b60e-be517698864d', - 'description': 'Стратегические предприятия и стратегические АО' - }, - { - 'name': 'facilitators', - 'uid': '202f2c7d-3cb2-41ae-aa14-817824b81a76', - 'description': 'Участники информационного ресурса фасилити-операторов' - }, - { - 'name': 'apk_charter', - 'uid': '3a255260-d236-476d-939f-6b1d947c110f', - 'description': 'Участники Хартии АПК' - }, - { - 'name': 'ats_charter', - 'uid': 'b15bc70b-611e-45d0-b836-9fdb123cb9c2', - 'description': 'Участники Хартии АТС' - }, - { - 'name': 'design_sro_members', - 'uid': '83b314dd-6ba1-4e66-a9bb-91affecd336b', - 'description': 'Члены СРО в области изысканий и (или) проектирования' - }, - { - 'name': 'construction_sro_members', - 'uid': 'a9278dcd-1999-4c0d-b467-dac85b09e337', - 'description': 'Члены СРО в области строительства' - }, -] diff --git a/kontur_focus/req.py b/kontur_focus/req.py index f82a167..a91c26d 100644 --- a/kontur_focus/req.py +++ b/kontur_focus/req.py @@ -10,20 +10,26 @@ class Request: """ base_url = None _access_key = None + _api_key = None content_type = None inn = None ogrn = None - def __init__(self, base_url: str, access_key: str, inn: str = None, ogrn: str = None): + def __init__(self, base_url: str, access_key: str = None, api_key: str = None, inn: str = None, ogrn: str = None): self.base_url = base_url self._access_key = access_key + self._api_key = api_key self.inn = inn self.ogrn = ogrn def get(self, path: str): full_url = f'{self.base_url}{path}' - payload = {'key': self._access_key, 'inn': self.inn, 'ogrn': self.ogrn} + if self._access_key: + payload = {'key': self._access_key, 'inn': self.inn, 'ogrn': self.ogrn} + elif self._api_key: + payload = {'api-key': self._api_key, 'inn': self.inn, 'ogrn': self.ogrn} + try: response = requests.get(url=full_url, params=payload)