forked from LiveCarta/BookConverter
Make todos & refactor code
This commit is contained in:
@@ -5,11 +5,10 @@ In parallel it updates status of a book conversion on admin panel.
|
||||
Finally sends result to server.
|
||||
Result is a json, JSON schema in book_schema.json
|
||||
"""
|
||||
|
||||
import codecs
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import json
|
||||
import codecs
|
||||
import logging
|
||||
import pathlib
|
||||
from abc import abstractmethod, ABCMeta
|
||||
|
||||
@@ -61,11 +60,11 @@ class BookSolver:
|
||||
"""
|
||||
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_doc(self.book_id)
|
||||
content = self.access.get_book(self.book_id)
|
||||
self.logger_object.log('File was received from server.')
|
||||
self.save_book_file(content)
|
||||
except FileNotFoundError as f_err:
|
||||
self.logger_object.log("Can't get docx from server.", logging.ERROR)
|
||||
self.logger_object.log("Can't get file from server.", logging.ERROR)
|
||||
self.logger_object.log_error_to_main_log()
|
||||
raise f_err
|
||||
except Exception as exc:
|
||||
@@ -109,8 +108,9 @@ class BookSolver:
|
||||
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}')
|
||||
@@ -121,6 +121,9 @@ class BookSolver:
|
||||
self.logger_object.log('End of the test.')
|
||||
|
||||
def conversion(self):
|
||||
'''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.')
|
||||
self.get_book_file()
|
||||
@@ -137,14 +140,14 @@ class BookSolver:
|
||||
raise exc
|
||||
|
||||
def conversion_local(self):
|
||||
'''Function
|
||||
without downloading book from server (local)
|
||||
with sending to server'''
|
||||
try:
|
||||
with open('tmp.json') as f:
|
||||
d = json.load(f)
|
||||
self.send_json_content_to_server(d)
|
||||
self.logger_object.log(f'End of the conversion to LiveCarta format. Check {self.output_path}.')
|
||||
|
||||
self.logger_object.log(f'Data has been downloaded from tmp.json file: {self.output_path}')
|
||||
with codecs.open('json/tmp.json', 'r', encoding='utf-8') as f_json:
|
||||
content_dict = json.load(f_json)
|
||||
self.send_json_content_to_server(content_dict)
|
||||
except Exception as exc:
|
||||
self.status_wrapper.set_error()
|
||||
self.logger_object.log('Error has occurred while conversion.', logging.ERROR)
|
||||
self.logger_object.log_error_to_main_log(str(exc))
|
||||
raise exc
|
||||
self.logger_object.log('Error has occurred while reading json file.' + str(exc), logging.ERROR)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user