From 8de1d0d0421146df484a23a023be105105679886 Mon Sep 17 00:00:00 2001 From: Kiryl Date: Fri, 29 Apr 2022 17:38:07 +0300 Subject: [PATCH] Fix local converter --- src/book_solver.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/book_solver.py b/src/book_solver.py index be11a0e..db14faa 100644 --- a/src/book_solver.py +++ b/src/book_solver.py @@ -36,8 +36,12 @@ class BookSolver: def save_book_file(self, content): """ - Save binary content of file to .docx/.epub. - :param content: binary content of the file. + Function saves binary content of file to .docx/.epub + Parameters + ---------- + content: str + binary content of the file + """ folder_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) folder_path = os.path.join(folder_path, f'{self.book_type}/{self.book_id}') @@ -56,7 +60,7 @@ class BookSolver: self.file_path = pathlib.Path(file_path) def get_book_file(self): - """ Method for getting and saving book from server. """ + """Method for getting and saving book from server""" try: self.logger_object.log(f'Start receiving file from server. URL: {self.access.url}/doc-convert/{self.book_id}/file') content = self.access.get_book(self.book_id) @@ -91,7 +95,7 @@ class BookSolver: self.logger_object.log('Error has occurred while writing json file.' + str(exc), logging.ERROR) def send_json_content_to_server(self, content: dict): - """ Function sends json_content to site """ + """Function sends json_content to site""" try: self.access.send_book(self.book_id, content) self.logger_object.log(f'JSON data has been sent to server.') @@ -112,6 +116,7 @@ class BookSolver: Function - with downloading book from server - with sending to server + """ try: self.logger_object.log(f'Beginning of conversion from .{self.book_type} to .json.') @@ -133,14 +138,15 @@ class BookSolver: Function - without downloading book from server (local) - with sending to server + """ try: - self.logger_object.log(f'Data has been downloaded from {file_name}.json file: {self.file_path}') + self.logger_object.log(f'Data has been downloaded from {file_name}.json file: ..\converter\json') self.status_wrapper.set_processing() with codecs.open(f'json/{file_name}.json', 'r', encoding='utf-8') as f_json: content_dict = json.load(f_json) self.send_json_content_to_server(content_dict) - self.logger_object.log(f'End of the conversion to LiveCarta format. Check {self.output_path}.') + self.logger_object.log(f'Sent a file to server. Check LiveCarta.') except Exception as exc: self.status_wrapper.set_error() self.logger_object.log('Error has occurred while reading json file.' + str(exc), logging.ERROR)