From ea37b19c36a772b57a89d2f935025fb09ab7e242 Mon Sep 17 00:00:00 2001 From: Kiryl Date: Tue, 6 Sep 2022 16:22:11 +0300 Subject: [PATCH] Move main to epub_solver.py --- src/epub_converter/epub_converter.py | 19 ------------------- src/epub_converter/epub_solver.py | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/epub_converter/epub_converter.py b/src/epub_converter/epub_converter.py index 7a0caf5..3ec04e2 100644 --- a/src/epub_converter/epub_converter.py +++ b/src/epub_converter/epub_converter.py @@ -1,6 +1,4 @@ import re -import json -import codecs import ebooklib from os import path from pathlib import Path @@ -605,20 +603,3 @@ class EpubConverter: "content": top_level_dict_chapters, "footnotes": self.footnotes_contents } - - -if __name__ == "__main__": - epub_file_path = "../../books/epub/9780763774134.epub" - logger_object = BookLogger( - name="epub", book_id=epub_file_path.split("/")[-1]) - - css_processor = StylePreprocessor() - html_processor = HtmlEpubProcessor( - "../../presets/epub_presets.json", logger=logger_object) - - json_converter = EpubConverter(epub_file_path, logger=logger_object, - style_processor=css_processor, html_processor=html_processor) - content_dict = json_converter.convert_to_dict() - - with codecs.open(epub_file_path.replace("epub", "json"), "w", encoding="utf-8") as f_json: - json.dump(content_dict, f_json, ensure_ascii=False) diff --git a/src/epub_converter/epub_solver.py b/src/epub_converter/epub_solver.py index 754b361..5aa13a0 100644 --- a/src/epub_converter/epub_solver.py +++ b/src/epub_converter/epub_solver.py @@ -1,6 +1,11 @@ +import json +import codecs + from src.book_solver import BookSolver +from src.util.helpers import BookLogger +from src.html_preprocessor import HtmlPreprocessor from src.style_preprocessor import StylePreprocessor -from src.epub_converter.html_epub_processor import HtmlEpubProcessor +from src.epub_converter.html_epub_processor import HTMLEpubProcessor from src.epub_converter.epub_converter import EpubConverter @@ -33,3 +38,22 @@ class EpubBook(BookSolver): style_processor=style_processor, html_processor=html_processor) content_dict = json_converter.convert_to_dict() return content_dict + + +if __name__ == "__main__": + epub_file_path = "../../books/epub/9780763774134.epub" + logger_object = BookLogger( + name="epub", book_id=epub_file_path.split("/")[-1]) + + html_preprocessor = HtmlPreprocessor( + logger=logger_object, preset_path="../../presets/epub_presets.json") + style_preprocessor = StylePreprocessor() + html_processor = HTMLEpubProcessor(logger=logger_object, + html_preprocessor=html_preprocessor) + + json_converter = EpubConverter(epub_file_path, logger=logger_object, + style_processor=style_preprocessor, html_processor=html_processor) + content_dict = json_converter.convert_to_dict() + + with codecs.open(epub_file_path.replace("epub", "json"), "w", encoding="utf-8") as f_json: + json.dump(content_dict, f_json, ensure_ascii=False)