forked from LiveCarta/BookConverter
epub converter: prettify solver.py
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
""" This is Interface for solving a task of a book conversion"""
|
||||
""" This is Main Abstract class for solving a task of a book conversion
|
||||
|
||||
Having an id of coming book, gets book from server, runs conversion.
|
||||
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 pathlib
|
||||
from abc import abstractmethod, ABCMeta
|
||||
|
||||
from livecarta_config import BookLogger, BookStatusWrapper, LawCartaConfig
|
||||
|
||||
|
||||
class BookSolver:
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __init__(self, book_id=0, access=None, main_logger=None, logging_format='%(asctime)s - %(levelname)s - %(message)s'):
|
||||
self.book_type = None
|
||||
@@ -82,7 +90,7 @@ class BookSolver:
|
||||
json.dump(content, f, ensure_ascii=False)
|
||||
self.logger_object.log(f'Data has been saved to .json file: {self.output_path}')
|
||||
except Exception as exc:
|
||||
self.logger_object.log('Error has occurred while writing json file.'+ str(exc), logging.ERROR)
|
||||
self.logger_object.log('Error has occurred while writing json file.' + str(exc), logging.ERROR)
|
||||
|
||||
def send_json_content_to_server(self, content: dict):
|
||||
try:
|
||||
@@ -94,6 +102,7 @@ class BookSolver:
|
||||
self.status_wrapper.set_error()
|
||||
raise exc
|
||||
|
||||
@abstractmethod
|
||||
def get_converted_book(self):
|
||||
self.logger_object.log('Beginning of processing json output.')
|
||||
self.status_wrapper.set_generating()
|
||||
@@ -106,7 +115,7 @@ class BookSolver:
|
||||
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 epub path: {self.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.')
|
||||
|
||||
Reference in New Issue
Block a user