From 871dd49b74999b6b3c58ccfe4472ee1b1b8d2264 Mon Sep 17 00:00:00 2001 From: shirshasa Date: Mon, 6 Sep 2021 18:37:30 +0300 Subject: [PATCH] epub converter: prettify solver.py --- src/solver.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/solver.py b/src/solver.py index e8646c1..0e2c04f 100644 --- a/src/solver.py +++ b/src/solver.py @@ -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.')