Preset support

This commit is contained in:
Kibzik
2023-03-15 12:56:51 +03:00
parent fc6fb4a625
commit 8e8c23d071
4 changed files with 19 additions and 22 deletions

View File

@@ -93,7 +93,6 @@ class Access:
}
response = requests.post(
f'{self.url}/token', json=json_form
# auth=('kiryl.miatselitsa', 'iK4yXCvdyHFEEOvG2v3F')
)
if response.status_code == 400:
@@ -160,7 +159,6 @@ class Access:
}
response = requests.post(
f'{self.url}/doc-convert/image', files=files, headers=self.headers
# auth=('kiryl.miatselitsa', 'iK4yXCvdyHFEEOvG2v3F')
)
img_obj.close()

View File

@@ -76,15 +76,14 @@ class BookSolver:
def get_preset_file(self):
"""Method for getting and saving preset from server"""
try:
pass
self.preset_path = "preset/docx_presets.json"
# self.logger_object.log(f"Start receiving preset file from server. URL:"
# f" {self.access.url}/doc-convert/{self.book_id}/preset")
self.book_logger.log(f"Start receiving preset file from server. URL:"
f" {self.access.url}/doc-convert/{self.book_id}/presets")
# content = self.access.get_file(
# file_path=f"{self.access.url}/doc-convert/{self.book_id}/preset")
# self.logger_object.log("Preset file was received from server.")
# file_path=f"{self.access.url}/doc-convert/{self.book_id}/presets")
# self.book_logger.log("Preset file was received from server.")
# self.preset_path = pathlib.Path(
# str(self.save_file(content, path_to_save="preset", file_type="json")))
self.preset_path = "preset/epub_presets.json"
except FileNotFoundError as f_err:
self.book_logger.log(
"Can't get preset file from server.", logging.ERROR)
@@ -169,8 +168,9 @@ class BookSolver:
f"Beginning of conversion from .{self.book_type} to .json.")
self.status_wrapper.set_processing()
content_dict: Dict[str, List[Dict[Union[str, List]]]] = self.get_converted_book()
# todo add delete of preset path
[os.remove(path) for path in [self.book_path]]
[os.remove(path) for path in [self.book_path,
# self.preset_path
]]
self.book_logger.log("Beginning of processing .json output.")
self.status_wrapper.set_generating()
self.write_to_json(content_dict)

View File

@@ -49,12 +49,12 @@ class DocxBook(BookSolver):
# 2. Parses and cleans html, gets list of tags, gets footnotes
try:
html_preprocessor = HtmlPresetsProcessor(
logger=self.book_logger, preset_path="preset/docx_presets.json")
html_preset_processor = HtmlPresetsProcessor(
logger=self.book_logger, preset_path=self.preset_path)
style_preprocessor = StyleReader()
html_processor = HtmlDocxProcessor(html_soup=html_converter.html_soup,
logger=self.book_logger,
html_preprocessor=html_preprocessor,
html_preprocessor=html_preset_processor,
style_preprocessor=style_preprocessor)
bs_tags, footnotes, top_level_headers = html_processor.process_html(
self.access, html_converter.html_path, self.book_id)
@@ -90,11 +90,11 @@ if __name__ == "__main__":
html_converter = Docx2LibreHtml(file_path=docx_file_path,
logger=book_logger, libre_locker=locker)
html_preprocessor = HtmlPresetsProcessor(
html_preset_processor = HtmlPresetsProcessor(
logger=book_logger, preset_path="../../preset/docx_presets.json")
style_preprocessor = StyleReader()
html_processor = HtmlDocxProcessor(html_soup=html_converter.html_soup, logger=book_logger,
html_preprocessor=html_preprocessor, style_preprocessor=style_preprocessor)
html_preprocessor=html_preset_processor, style_preprocessor=style_preprocessor)
content, footnotes, top_level_headers = html_processor.process_html(
html_path=html_converter.html_path, book_id=html_converter.book_id)

View File

@@ -34,10 +34,10 @@ class EpubBook(BookSolver):
style_preprocessor = StyleReader()
# Parses and cleans html, gets list of tags, gets footnotes
try:
html_preprocessor = HtmlPresetsProcessor(
logger=self.book_logger, preset_path="preset/epub_presets.json")
html_preset_processor = HtmlPresetsProcessor(
logger=self.book_logger, preset_path=self.preset_path)
html_processor = HtmlEpubProcessor(logger=self.book_logger,
html_preprocessor=html_preprocessor)
html_preprocessor=html_preset_processor)
except Exception as exc:
self.book_logger.log(
"Error has occurred while processing .html", logging.ERROR)
@@ -52,17 +52,16 @@ class EpubBook(BookSolver):
if __name__ == "__main__":
epub_file_path = f"../../books/epub/Deep_Learning_with_Python_Second_Editio.epub"
epub_file_path = f"../../books/epub/9781260455076.epub"
logger_object = BookLogger(name="epub")
logger_object.configure_book_logger(book_id=epub_file_path.split("/")[-1])
html_preprocessor = HtmlPresetsProcessor(
html_preset_processor = HtmlPresetsProcessor(
logger=logger_object, preset_path="../../preset/epub_presets.json")
style_preprocessor = StyleReader()
html_processor = HtmlEpubProcessor(logger=logger_object,
html_preprocessor=html_preprocessor)
html_preprocessor=html_preset_processor)
json_converter = EpubConverter(epub_file_path, logger=logger_object,
style_processor=style_preprocessor, html_processor=html_processor)