Small changes (to work with preset)

This commit is contained in:
Kiryl
2022-07-27 20:20:28 +03:00
parent 84b692d39b
commit 617d4fcaef
2 changed files with 29 additions and 29 deletions

View File

@@ -35,22 +35,6 @@ class Access:
self.get_token()
self.refreshing.set()
def sleep(timeout: float, retry=3):
def decorator(function):
"""Decorator sleeping timeout sec and makes 3 retries"""
def wrapper(*args, **kwargs):
retries = 0
while retries < retry:
try:
value = function(*args, **kwargs)
if value is not None:
return value
except:
time.sleep(timeout)
retries += 1
return wrapper
return decorator
def set_credentials(self, url):
folder_path = os.path.dirname(
os.path.dirname(os.path.abspath(__file__)))
@@ -60,8 +44,8 @@ class Access:
self.refreshing.clear()
self.url = url
self.username = params['username']
self.password = params['password']
self.username = params["username"]
self.password = params["password"]
self.refreshing.set()
def format_header(self):
@@ -123,14 +107,14 @@ class Access:
else:
raise Exception(f'{response.status_code}')
def get_book(self, book_id):
"""Function downloads the book from site"""
def get_file(self, file_path):
"""Function downloads the file[book, preset] from site"""
if self.is_time_for_refreshing():
self.refresh_token()
self.refreshing.wait()
response = requests.get(
f'{self.url}/doc-convert/{book_id}/file', headers=self.headers,
file_path, headers=self.headers,
# auth=('kiryl.miatselitsa', 'iK4yXCvdyHFEEOvG2v3F')
)
@@ -139,11 +123,26 @@ class Access:
elif response.status_code == 200:
content = response.content
else:
raise Exception(f'Error in getting doc from url: {self.url}/doc-convert/{book_id}/file, '
raise Exception(f'Error in getting preset from url: {file_path}, '
f'status code:{response.status_code}')
return content
def sleep(timeout: float, retry=3):
def decorator(function):
"""Decorator sleeping timeout sec and makes 3 retries"""
def wrapper(*args, **kwargs):
retries = 0
while retries < retry:
try:
value = function(*args, **kwargs)
if value is not None:
return value
except:
time.sleep(timeout)
retries += 1
return wrapper
return decorator
@sleep(3)
def send_image(self, img_path, doc_id, img_content: bytes = None):
"""Function sends images to site"""