forked from LiveCarta/BookConverter
Rewrite local converting
This commit is contained in:
@@ -107,21 +107,6 @@ class BookSolver:
|
||||
self.status_wrapper.set_generating()
|
||||
return {}
|
||||
|
||||
def test_conversion(self):
|
||||
"""
|
||||
Function
|
||||
- without sending to server
|
||||
"""
|
||||
self.logger_object.log('Beginning of the test.')
|
||||
folder_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
folder_path = os.path.join(folder_path, f'{self.book_type}')
|
||||
file_path = os.path.join(folder_path, f'{self.book_id}.{self.book_type}')
|
||||
self.file_path = pathlib.Path(file_path)
|
||||
self.logger_object.log(f'Test on {self.book_type}: {self.file_path}')
|
||||
content_dict = self.get_converted_book()
|
||||
self.write_to_json(content_dict)
|
||||
self.logger_object.log('End of the test.')
|
||||
|
||||
def conversion(self):
|
||||
"""
|
||||
Function
|
||||
@@ -143,17 +128,20 @@ class BookSolver:
|
||||
self.logger_object.log_error_to_main_log(str(exc))
|
||||
raise exc
|
||||
|
||||
def conversion_local(self):
|
||||
def conversion_local(self, file_name: str):
|
||||
"""
|
||||
Function
|
||||
- without downloading book from server (local)
|
||||
- with sending to server
|
||||
"""
|
||||
try:
|
||||
self.logger_object.log(f'Data has been downloaded from tmp.json file: {self.file_path}')
|
||||
with codecs.open('json/tmp.json', 'r', encoding='utf-8') as f_json:
|
||||
self.logger_object.log(f'Data has been downloaded from {file_name}.json file: {self.file_path}')
|
||||
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}.')
|
||||
except Exception as exc:
|
||||
self.logger_object.log('Error has occurred while reading json file.' + str(exc), logging.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_to_main_log(str(exc))
|
||||
Reference in New Issue
Block a user