change structure of project

This commit is contained in:
Kiryl
2021-09-30 13:08:09 +03:00
parent 61d85f6c22
commit af1b6138a9
5 changed files with 35 additions and 18 deletions

View File

@@ -9,8 +9,8 @@ from premailer import transform
from itertools import takewhile
from logging import CRITICAL
from livecarta_config import LiveCartaConfig
from util.color_reader import str2hex
from src.livecarta_config import LiveCartaConfig
from src.util.color_reader import str2hex
cssutils.log.setLevel(CRITICAL)
@@ -252,7 +252,6 @@ class TagStyleConverter:
if item[0] in ['text-indent', 'margin-left']:
item[1] = convert_indents(item[1])
clean_style += item[0] + ': ' + item[1] + '; '
print(clean_style, '\n')
margin_left_regexp = re.compile(
r'(margin-left:( *-*\w+);*)')
@@ -482,7 +481,7 @@ def convert_html_soup_with_css_style(html_soup: BeautifulSoup, css_text: str):
if __name__ == '__main__':
file = '../epub/9781627222174.epub'
file = '../../epub/9781627222174.epub'
ebooklib_book = epub.read_epub(file)
css_ = ebooklib_book.get_item_with_href('css/epub.css')
css_ = css_.get_content().decode()

View File

@@ -13,13 +13,12 @@ from bs4 import BeautifulSoup, Tag
from ebooklib import epub
from ebooklib.epub import Link, Section
from data_objects import ChapterItem, NavPoint
from html_epub_preprocessor import unwrap_structural_tags, get_tags_between_chapter_marks, prepare_title_and_content, \
from src.data_objects import ChapterItem, NavPoint
from src.epub_converter.html_epub_preprocessor import unwrap_structural_tags, get_tags_between_chapter_marks, prepare_title_and_content, \
update_src_links_in_images, preprocess_footnotes
from css_reader import build_css_content, convert_html_soup_with_css_style
from livecarta_config import LiveCartaConfig
from util.helpers import BookLogger
from src.epub_converter.css_reader import build_css_content, convert_html_soup_with_css_style
from src.livecarta_config import LiveCartaConfig
from src.util.helpers import BookLogger
class EpubConverter:
@@ -149,13 +148,16 @@ class EpubConverter:
return html_href2css_href, css_href2css_content,
def add_css_styles_to_html_soup(self):
'''
This function is designed to update html_href2html_body_soup
And add to html_inline_style css_style_content
'''
for href in self.html_href2html_body_soup:
if self.html_href2css_href.get(href):
css =''
for key in self.html_href2css_href[href]:
css += self.css_href2css_content[key]
content: BeautifulSoup = self.html_href2html_body_soup[href]
# todo func here to make content
content = convert_html_soup_with_css_style(content, css)
self.html_href2html_body_soup[href] = content
@@ -450,12 +452,12 @@ if __name__ == "__main__":
logger = logging.getLogger('epub')
file_handler = logging.StreamHandler()
logger.addHandler(file_handler)
file_handler = logging.FileHandler('epub.log', mode='w+')
file_handler = logging.FileHandler('../epub.log', mode='w+')
logger.addHandler(file_handler)
logger_object = BookLogger(name=f'epub', main_logger=logger, book_id=0)
json_converter = EpubConverter('../epub/9781641053532.epub',
json_converter = EpubConverter('../../epub/9781634252221.epub',
logger=logger_object)
tmp = json_converter.convert_to_dict()

View File

@@ -1,5 +1,5 @@
from epub_converter import EpubConverter
from book_solver import BookSolver
from src.epub_converter.epub_converter import EpubConverter
from src.book_solver import BookSolver
class EpubBook(BookSolver):

View File

@@ -5,13 +5,13 @@ from typing import Tuple
from bs4 import BeautifulSoup, NavigableString, Tag, Comment
from access import Access
from livecarta_config import LiveCartaConfig
from src.access import Access
from src.livecarta_config import LiveCartaConfig
def save_image_locally(img_file_path, img_content, book_id):
folder_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
new_path = pathlib.Path(os.path.join(folder_path, f'json/img_{book_id}/'))
new_path = pathlib.Path(os.path.join(folder_path, f'../json/img_{book_id}/'))
new_path.mkdir(exist_ok=True)
new_img_path = new_path / os.path.basename(img_file_path)

View File

@@ -0,0 +1,16 @@
from src.book_solver import BookSolver
class XmlBook(BookSolver):
def __init__(self, book_id=0, access=None, main_logger=None,
logging_format='%(asctime)s - %(levelname)s - %(message)s'):
super().__init__(book_id, access, main_logger, logging_format)
self.book_type = 'xml'
def get_converted_book(self):
pass
#json_converter = XmlConverter(self.file_path, access=self.access, logger=self.logger_object)
#content_dict = json_converter.convert_to_dict()
#self.status_wrapper.set_generating()
#return content_dict