From 6fcb30c49728a84f96db1190e10180ffc50b44fe Mon Sep 17 00:00:00 2001 From: Ilya Sapunov Date: Wed, 12 Mar 2025 19:03:13 +0300 Subject: [PATCH] Updated requests, added express_report --- kontur_focus/focus.py | 29 ++++++++++++++++++++++++++--- kontur_focus/req.py | 6 ++++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/kontur_focus/focus.py b/kontur_focus/focus.py index 8e7a514..a390b6b 100644 --- a/kontur_focus/focus.py +++ b/kontur_focus/focus.py @@ -1,6 +1,7 @@ import os from dotenv import load_dotenv from kontur_focus.req import Request +from datetime import datetime class Focus(Request): @@ -40,7 +41,8 @@ class Focus(Request): :rtype: str """ 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: file_path = os.path.join(self._basedir, filename) @@ -55,6 +57,27 @@ class Focus(Request): except Exception: 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): """История владения организацией @@ -71,7 +94,7 @@ class Focus(Request): """ return self.get('/foreignRepresentatives') - def government_lists(self): + def government_lists(self): # DEPRECATED """Вхождение организации в государственные реестры :return: Список реестров @@ -81,7 +104,7 @@ class Focus(Request): return response['listsEntries'] - def is_foreign_agent(self): + def is_foreign_agent(self): # DEPRECATED """Проверка наличия организации в Едином реестре иностранных агентов :return: Результат проверки diff --git a/kontur_focus/req.py b/kontur_focus/req.py index a91c26d..1aa23c4 100644 --- a/kontur_focus/req.py +++ b/kontur_focus/req.py @@ -22,14 +22,16 @@ class Request: self.inn = inn self.ogrn = ogrn - def get(self, path: str): + def get(self, path: str, **add_params): full_url = f'{self.base_url}{path}' if self._access_key: payload = {'key': self._access_key, 'inn': self.inn, 'ogrn': self.ogrn} + payload.update(add_params) elif self._api_key: payload = {'api-key': self._api_key, 'inn': self.inn, 'ogrn': self.ogrn} - + payload.update(add_params) + try: response = requests.get(url=full_url, params=payload)