Added method for downloading reports in PDF, added packaging tools.

This commit is contained in:
2024-05-02 16:03:21 +03:00
parent 78f1864576
commit 59f420c725
3 changed files with 49 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ class Focus:
_access_key = None
_inn = None
_orgn = None
_basedir = os.path.abspath(os.path.dirname(__file__))
def __init__(self, inn: str, ogrn: str = None):
load_dotenv()
@@ -21,7 +22,15 @@ class Focus:
full_url = f'{self._base_url}{path}'
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):
return self._r_get('/req')
@@ -29,6 +38,23 @@ class Focus:
def advanced_info(self):
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):
return self._r_get('/foundersHistory')