Updated requests, added express_report
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from kontur_focus.req import Request
|
from kontur_focus.req import Request
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class Focus(Request):
|
class Focus(Request):
|
||||||
@@ -40,7 +41,8 @@ class Focus(Request):
|
|||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
response = self.get('/excerpt')
|
response = self.get('/excerpt')
|
||||||
filename = f'{self.inn}_report.pdf'
|
current_datetime = datetime.now().strftime('%d-%m-%Y_%H-%M')
|
||||||
|
filename = f'Выписка_{self.inn}_{current_datetime}.pdf'
|
||||||
|
|
||||||
if not path:
|
if not path:
|
||||||
file_path = os.path.join(self._basedir, filename)
|
file_path = os.path.join(self._basedir, filename)
|
||||||
@@ -55,6 +57,27 @@ class Focus(Request):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return 'Saving error!'
|
return 'Saving error!'
|
||||||
|
|
||||||
|
def express_report(self, pdf: bool = True, path: str = None):
|
||||||
|
response = self.get('/briefReport', pdf=pdf)
|
||||||
|
current_datetime = datetime.now().strftime('%d-%m-%Y_%H-%M')
|
||||||
|
filename = f'Экспресс-отчет_{self.inn}_{current_datetime}.pdf'
|
||||||
|
|
||||||
|
if pdf:
|
||||||
|
if not path:
|
||||||
|
file_path = os.path.join(self._basedir, filename)
|
||||||
|
else:
|
||||||
|
file_path = os.path.join(path, filename)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(file_path, mode='wb') as file:
|
||||||
|
file.write(response.content)
|
||||||
|
|
||||||
|
return f'File {file_path} saved'
|
||||||
|
except Exception:
|
||||||
|
return 'Saving error!'
|
||||||
|
else:
|
||||||
|
return response
|
||||||
|
|
||||||
def founders_history(self):
|
def founders_history(self):
|
||||||
"""История владения организацией
|
"""История владения организацией
|
||||||
|
|
||||||
@@ -71,7 +94,7 @@ class Focus(Request):
|
|||||||
"""
|
"""
|
||||||
return self.get('/foreignRepresentatives')
|
return self.get('/foreignRepresentatives')
|
||||||
|
|
||||||
def government_lists(self):
|
def government_lists(self): # DEPRECATED
|
||||||
"""Вхождение организации в государственные реестры
|
"""Вхождение организации в государственные реестры
|
||||||
|
|
||||||
:return: Список реестров
|
:return: Список реестров
|
||||||
@@ -81,7 +104,7 @@ class Focus(Request):
|
|||||||
|
|
||||||
return response['listsEntries']
|
return response['listsEntries']
|
||||||
|
|
||||||
def is_foreign_agent(self):
|
def is_foreign_agent(self): # DEPRECATED
|
||||||
"""Проверка наличия организации в Едином реестре иностранных агентов
|
"""Проверка наличия организации в Едином реестре иностранных агентов
|
||||||
|
|
||||||
:return: Результат проверки
|
:return: Результат проверки
|
||||||
|
|||||||
@@ -22,14 +22,16 @@ class Request:
|
|||||||
self.inn = inn
|
self.inn = inn
|
||||||
self.ogrn = ogrn
|
self.ogrn = ogrn
|
||||||
|
|
||||||
def get(self, path: str):
|
def get(self, path: str, **add_params):
|
||||||
full_url = f'{self.base_url}{path}'
|
full_url = f'{self.base_url}{path}'
|
||||||
|
|
||||||
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}
|
||||||
|
payload.update(add_params)
|
||||||
elif self._api_key:
|
elif self._api_key:
|
||||||
payload = {'api-key': self._api_key, 'inn': self.inn, 'ogrn': self.ogrn}
|
payload = {'api-key': self._api_key, 'inn': self.inn, 'ogrn': self.ogrn}
|
||||||
|
payload.update(add_params)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(url=full_url, params=payload)
|
response = requests.get(url=full_url, params=payload)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user