forked from LiveCarta/BookConverter
Fix local converter
This commit is contained in:
@@ -36,8 +36,12 @@ class BookSolver:
|
|||||||
|
|
||||||
def save_book_file(self, content):
|
def save_book_file(self, content):
|
||||||
"""
|
"""
|
||||||
Save binary content of file to .docx/.epub.
|
Function saves binary content of file to .docx/.epub
|
||||||
:param content: binary content of the file.
|
Parameters
|
||||||
|
----------
|
||||||
|
content: str
|
||||||
|
binary content of the file
|
||||||
|
|
||||||
"""
|
"""
|
||||||
folder_path = os.path.dirname(os.path.dirname(os.path.abspath(__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}')
|
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)
|
self.file_path = pathlib.Path(file_path)
|
||||||
|
|
||||||
def get_book_file(self):
|
def get_book_file(self):
|
||||||
""" Method for getting and saving book from server. """
|
"""Method for getting and saving book from server"""
|
||||||
try:
|
try:
|
||||||
self.logger_object.log(f'Start receiving file from server. URL: {self.access.url}/doc-convert/{self.book_id}/file')
|
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)
|
content = self.access.get_book(self.book_id)
|
||||||
@@ -112,6 +116,7 @@ class BookSolver:
|
|||||||
Function
|
Function
|
||||||
- with downloading book from server
|
- with downloading book from server
|
||||||
- with sending to server
|
- with sending to server
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.logger_object.log(f'Beginning of conversion from .{self.book_type} to .json.')
|
self.logger_object.log(f'Beginning of conversion from .{self.book_type} to .json.')
|
||||||
@@ -133,14 +138,15 @@ class BookSolver:
|
|||||||
Function
|
Function
|
||||||
- without downloading book from server (local)
|
- without downloading book from server (local)
|
||||||
- with sending to server
|
- with sending to server
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
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()
|
self.status_wrapper.set_processing()
|
||||||
with codecs.open(f'json/{file_name}.json', 'r', encoding='utf-8') as f_json:
|
with codecs.open(f'json/{file_name}.json', 'r', encoding='utf-8') as f_json:
|
||||||
content_dict = json.load(f_json)
|
content_dict = json.load(f_json)
|
||||||
self.send_json_content_to_server(content_dict)
|
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:
|
except Exception as exc:
|
||||||
self.status_wrapper.set_error()
|
self.status_wrapper.set_error()
|
||||||
self.logger_object.log('Error has occurred while reading json file.' + str(exc), logging.ERROR)
|
self.logger_object.log('Error has occurred while reading json file.' + str(exc), logging.ERROR)
|
||||||
|
|||||||
Reference in New Issue
Block a user