Added method for downloading reports in PDF, added packaging tools.
This commit is contained in:
@@ -9,6 +9,7 @@ class Focus:
|
|||||||
_access_key = None
|
_access_key = None
|
||||||
_inn = None
|
_inn = None
|
||||||
_orgn = None
|
_orgn = None
|
||||||
|
_basedir = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
def __init__(self, inn: str, ogrn: str = None):
|
def __init__(self, inn: str, ogrn: str = None):
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@@ -21,7 +22,15 @@ class Focus:
|
|||||||
full_url = f'{self._base_url}{path}'
|
full_url = f'{self._base_url}{path}'
|
||||||
payload = {'key': self._access_key, 'inn': self._inn, 'ogrn': self._orgn}
|
payload = {'key': self._access_key, 'inn': self._inn, 'ogrn': self._orgn}
|
||||||
|
|
||||||
return requests.get(url=full_url, params=payload).json()
|
try:
|
||||||
|
response = requests.get(url=full_url, params=payload)
|
||||||
|
|
||||||
|
if response.headers['Content-Type'] == 'application/pdf':
|
||||||
|
return response
|
||||||
|
else:
|
||||||
|
return response.json()
|
||||||
|
except Exception:
|
||||||
|
return 'Request error!'
|
||||||
|
|
||||||
def base_info(self):
|
def base_info(self):
|
||||||
return self._r_get('/req')
|
return self._r_get('/req')
|
||||||
@@ -29,6 +38,23 @@ class Focus:
|
|||||||
def advanced_info(self):
|
def advanced_info(self):
|
||||||
return self._r_get('/egrDetails')
|
return self._r_get('/egrDetails')
|
||||||
|
|
||||||
|
def excerpt(self, path=None):
|
||||||
|
response = self._r_get('/excerpt')
|
||||||
|
filename = f'{self._inn}_report.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 'File saved'
|
||||||
|
except Exception:
|
||||||
|
return 'Saving error!'
|
||||||
|
|
||||||
def founders_history(self):
|
def founders_history(self):
|
||||||
return self._r_get('/foundersHistory')
|
return self._r_get('/foundersHistory')
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
requests
|
requests
|
||||||
python-dotenv
|
python-dotenv
|
||||||
|
twine
|
||||||
|
wheel
|
||||||
19
setup.py
Normal file
19
setup.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name="kontur_focus",
|
||||||
|
version="0.1.0",
|
||||||
|
author="Ilya Sapunov",
|
||||||
|
author_email="sapunov@selectel.ru",
|
||||||
|
description="Библиотека-обертка для взаимодействия с REST API Контур.Фокус",
|
||||||
|
url="https://git.selectel.org/is/public/kontur-focus-lib",
|
||||||
|
license="MIT",
|
||||||
|
packages=find_packages(),
|
||||||
|
install_requires=["requests", "python-dotenv"],
|
||||||
|
classifiers=[
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
],
|
||||||
|
python_requires='>=3.9',
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user