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 codecs
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
from abc import abstractmethod, ABCMeta
|
||||||
|
|
||||||
from livecarta_config import BookLogger, BookStatusWrapper, LawCartaConfig
|
from livecarta_config import BookLogger, BookStatusWrapper, LawCartaConfig
|
||||||
|
|
||||||
|
|
||||||
class BookSolver:
|
class BookSolver:
|
||||||
|
__metaclass__ = ABCMeta
|
||||||
|
|
||||||
def __init__(self, book_id=0, access=None, main_logger=None, logging_format='%(asctime)s - %(levelname)s - %(message)s'):
|
def __init__(self, book_id=0, access=None, main_logger=None, logging_format='%(asctime)s - %(levelname)s - %(message)s'):
|
||||||
self.book_type = None
|
self.book_type = None
|
||||||
@@ -94,6 +102,7 @@ class BookSolver:
|
|||||||
self.status_wrapper.set_error()
|
self.status_wrapper.set_error()
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def get_converted_book(self):
|
def get_converted_book(self):
|
||||||
self.logger_object.log('Beginning of processing json output.')
|
self.logger_object.log('Beginning of processing json output.')
|
||||||
self.status_wrapper.set_generating()
|
self.status_wrapper.set_generating()
|
||||||
@@ -106,7 +115,7 @@ class BookSolver:
|
|||||||
folder_path = os.path.join(folder_path, f'{self.book_type}')
|
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}')
|
file_path = os.path.join(folder_path, f'{self.book_id}.{self.book_type}')
|
||||||
self.file_path = pathlib.Path(file_path)
|
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()
|
content_dict = self.get_converted_book()
|
||||||
self.write_to_json(content_dict)
|
self.write_to_json(content_dict)
|
||||||
self.logger_object.log('End of the test.')
|
self.logger_object.log('End of the test.')
|
||||||
|
|||||||
Reference in New Issue
Block a user