Updated settings for VScode, updated focus_compliance, fixed req
This commit is contained in:
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,3 +1,6 @@
|
|||||||
{
|
{
|
||||||
"python-envs.pythonProjects": []
|
"python-envs.pythonProjects": [],
|
||||||
|
"files.autoSave": "onFocusChange",
|
||||||
|
"editor.fontSize": 13,
|
||||||
|
"autoDocstring.docstringFormat": "sphinx"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
from kontur_focus.req import Request
|
from kontur_focus.req import Request
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class FocusCompliance(Request):
|
class FocusCompliance(Request):
|
||||||
@@ -17,8 +18,25 @@ class FocusCompliance(Request):
|
|||||||
)
|
)
|
||||||
self._focus_base_url = f'/banks/{os.environ.get('FOCUS_COMPLIANCE_BANK_ID')}'
|
self._focus_base_url = f'/banks/{os.environ.get('FOCUS_COMPLIANCE_BANK_ID')}'
|
||||||
|
|
||||||
|
def _save_file(self, filename: str, content, file_type: str = 'pdf', path: str = None) -> dict:
|
||||||
|
current_datetime = datetime.now().strftime('%d-%m-%Y_%H-%M')
|
||||||
|
f_name = f'{filename}_{self.inn}_{current_datetime}.{file_type}'
|
||||||
|
|
||||||
|
if not path:
|
||||||
|
file_path = os.path.join(self._basedir, f_name)
|
||||||
|
else:
|
||||||
|
file_path = os.path.join(path, f_name)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(file_path, mode='wb') as file:
|
||||||
|
file.write(content)
|
||||||
|
|
||||||
|
return {'success': True, 'path': file_path}
|
||||||
|
except Exception as e:
|
||||||
|
return {'success': False, 'message': e}
|
||||||
|
|
||||||
# Компании
|
# Компании
|
||||||
def company_is_foreign_agent(self):
|
def company_is_foreign_agent(self) -> dict:
|
||||||
"""Вхождение организации и ее руководителей в список иностранных агентов
|
"""Вхождение организации и ее руководителей в список иностранных агентов
|
||||||
|
|
||||||
:return: Дата формирования реестра, а также признаки присутствия или отсутствия в списках иностранных агентов
|
:return: Дата формирования реестра, а также признаки присутствия или отсутствия в списках иностранных агентов
|
||||||
@@ -49,6 +67,59 @@ class FocusCompliance(Request):
|
|||||||
|
|
||||||
return fal_data
|
return fal_data
|
||||||
|
|
||||||
|
def search_global_company_profiles_id(self) -> list:
|
||||||
|
"""Поиск сводной информации по санкционным профилям ЮЛ
|
||||||
|
|
||||||
|
:return: Список идентификаторов профилей
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
|
response = self.get(f'{self._focus_base_url}/companies/profiles/search', query=self.inn)
|
||||||
|
profiles = response['legalEntityProfiles']
|
||||||
|
|
||||||
|
if not profiles:
|
||||||
|
return profiles
|
||||||
|
elif len(profiles) > 1:
|
||||||
|
return [profile['id'] for profile in profiles]
|
||||||
|
else:
|
||||||
|
return [profiles[0]['id']]
|
||||||
|
|
||||||
|
def legal_entity_profile_report(self, profile_id_list: list, path: str = None) -> dict:
|
||||||
|
"""Получение печатного отчета по профилю ЮЛ
|
||||||
|
|
||||||
|
:param profile_id_list: Список идентификаторов санкционных профилей компании
|
||||||
|
:type profile_id_list: list
|
||||||
|
:param path: Путь сохранения файла, по-умолчанию файл сохраняется в текущий каталог
|
||||||
|
:type path: str, optional
|
||||||
|
:return: Отчет о результате сохранения файла
|
||||||
|
:rtype: dict
|
||||||
|
"""
|
||||||
|
if not profile_id_list:
|
||||||
|
return {'success': False, 'message': 'No profiles is specified'}
|
||||||
|
elif len(profile_id_list) > 1:
|
||||||
|
files = []
|
||||||
|
|
||||||
|
for profile_id in profile_id_list:
|
||||||
|
response = self.get(f'{self._focus_base_url}/companies/profiles/{profile_id}/report')
|
||||||
|
result = self._save_file(
|
||||||
|
filename=f'Отчет_по_профилю_{profile_id_list[0]}',
|
||||||
|
content=response.content,
|
||||||
|
file_type='docx',
|
||||||
|
path=path
|
||||||
|
)
|
||||||
|
files.append(result)
|
||||||
|
|
||||||
|
return files
|
||||||
|
else:
|
||||||
|
response = self.get(f'{self._focus_base_url}/companies/profiles/{profile_id_list[0]}/report')
|
||||||
|
result = self._save_file(
|
||||||
|
filename=f'Отчет_по_профилю_{profile_id_list[0]}',
|
||||||
|
content=response.content,
|
||||||
|
file_type='docx',
|
||||||
|
path=path
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
# Физлица
|
# Физлица
|
||||||
def person_is_foreign_agent(self):
|
def person_is_foreign_agent(self):
|
||||||
"""Вхождение физлица в список иностранных агентов
|
"""Вхождение физлица в список иностранных агентов
|
||||||
@@ -60,3 +131,8 @@ class FocusCompliance(Request):
|
|||||||
fa = response[0]['foreignAgents']
|
fa = response[0]['foreignAgents']
|
||||||
|
|
||||||
return True if fa else False
|
return True if fa else False
|
||||||
|
|
||||||
|
def get_foreign_agents_list(self): # Не работает, если нет подключенной лицензии
|
||||||
|
response = self.get(path=f'{self._focus_base_url}/foreign-agents')
|
||||||
|
|
||||||
|
return response
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class Request:
|
|||||||
|
|
||||||
def get(self, path: str, **add_params):
|
def get(self, path: str, **add_params):
|
||||||
full_url = f'{self.base_url}{path}'
|
full_url = f'{self.base_url}{path}'
|
||||||
|
payload = None
|
||||||
|
|
||||||
if self._access_key:
|
if self._access_key:
|
||||||
payload = {'key': self._access_key, 'inn': self.inn, 'ogrn': self.ogrn}
|
payload = {'key': self._access_key, 'inn': self.inn, 'ogrn': self.ogrn}
|
||||||
@@ -35,9 +36,10 @@ class Request:
|
|||||||
try:
|
try:
|
||||||
response = requests.get(url=full_url, params=payload)
|
response = requests.get(url=full_url, params=payload)
|
||||||
|
|
||||||
if response.headers['Content-Type'] == 'application/pdf':
|
if response.headers['Content-Type'] == 'application/json' or \
|
||||||
return response
|
response.headers['Content-Type'] == 'application/json; charset=utf-8':
|
||||||
else:
|
|
||||||
return response.json()
|
return response.json()
|
||||||
|
else:
|
||||||
|
return response
|
||||||
except RequestException as e:
|
except RequestException as e:
|
||||||
return f'Error: {e}'
|
return f'Error: {e}'
|
||||||
|
|||||||
Reference in New Issue
Block a user