Change Law -> Live

This commit is contained in:
Kiryl
2021-09-29 20:22:47 +03:00
parent 7cf90b25f7
commit 61d85f6c22
5 changed files with 20 additions and 21 deletions

View File

@@ -129,7 +129,7 @@ class BookSolver:
content_dict = self.get_converted_book()
self.write_to_json(content_dict)
self.send_json_content_to_server(content_dict)
self.logger_object.log(f'End of the conversion to LawCarta format. Check {self.output_path}.')
self.logger_object.log(f'End of the conversion to LiveCarta format. Check {self.output_path}.')
except Exception as exc:
self.status_wrapper.set_error()
@@ -142,7 +142,7 @@ class BookSolver:
with open('tmp.json') as f:
d = json.load(f)
self.send_json_content_to_server(d)
self.logger_object.log(f'End of the conversion to LawCarta format. Check {self.output_path}.')
self.logger_object.log(f'End of the conversion to LiveCarta format. Check {self.output_path}.')
except Exception as exc:
self.status_wrapper.set_error()

View File

@@ -30,7 +30,7 @@ list_types = ['circle', 'disc', 'armenian', 'decimal',
def convert_font_size(value):
if 'pt' in value:
if int(value.replace('pt', '')) == LiveCartaConfig.LAWCARTA_DEFAULT_FONT_SIZE:
if int(value.replace('pt', '')) == LiveCartaConfig.LIVECARTA_DEFAULT_FONT_SIZE:
return ''
else:
return value.replace('pt', 'px')
@@ -252,6 +252,7 @@ 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+);*)')
@@ -266,24 +267,22 @@ class TagStyleConverter:
filter(str.isdigit, str(has_margin_left.group(2))))))
if has_text_indent:
if has_text_indent.group(1):
num_ti = abs(int("".join(
filter(str.isdigit, str(has_text_indent.group(2))))))
clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' +
str(abs(num_ml - num_ti)) + 'px; ')
clean_style = clean_style.replace(has_margin_left.group(1), '')
return clean_style
num_ti = abs(int("".join(
filter(str.isdigit, str(has_text_indent.group(2))))))
clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' +
str(abs(num_ml - num_ti)) + 'px; ')
clean_style = clean_style.replace(has_margin_left.group(1), '')
return clean_style
clean_style = clean_style.replace(has_margin_left.group(1), 'text-indent: ' +
str(abs(num_ml)) + 'px; ')
return clean_style
elif has_text_indent:
if has_text_indent.group(1):
clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' +
str(abs(int("".join(
filter(str.isdigit, str(has_text_indent.group(2))))))) + 'px; ')
return clean_style
clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' +
str(abs(int("".join(
filter(str.isdigit, str(has_text_indent.group(2))))))) + 'px; ')
return clean_style
return clean_style
def preprocess_style(self):

View File

@@ -455,7 +455,7 @@ if __name__ == "__main__":
logger_object = BookLogger(name=f'epub', main_logger=logger, book_id=0)
json_converter = EpubConverter('../epub/Cook.epub',
json_converter = EpubConverter('../epub/9781641053532.epub',
logger=logger_object)
tmp = json_converter.convert_to_dict()

View File

@@ -53,7 +53,7 @@ class HTMLDocxPreprocessor:
def convert_pt_to_px(cls, value):
value = float(value)
if value == LiveCartaConfig.WORD_DEFAULT_FONT_SIZE:
return LiveCartaConfig.LAWCARTA_DEFAULT_FONT_SIZE
return LiveCartaConfig.LIVECARTA_DEFAULT_FONT_SIZE
else:
return value
@@ -73,7 +73,7 @@ class HTMLDocxPreprocessor:
size = size.group(1)
new_size = cls.convert_pt_to_px(size)
if new_size == LiveCartaConfig.LAWCARTA_DEFAULT_FONT_SIZE:
if new_size == LiveCartaConfig.LIVECARTA_DEFAULT_FONT_SIZE:
return ""
return re.sub(size + "pt", str(new_size) + "px", style)
@@ -635,7 +635,7 @@ class HTMLDocxPreprocessor:
def process_html(self, access, html_path, book_id):
"""
Process html code to satisfy LawCarta formatting.
Process html code to satisfy LiveCarta formatting.
"""
try:
self.logger_object.log(f'Processing TOC and headers.')

View File

@@ -9,8 +9,8 @@ class LiveCartaConfig:
DEFAULT_ALIGN_STYLE = 'left'
ALIGN_STYLES = ['justify', 'right', 'center', 'left']
WORD_DEFAULT_FONT_SIZE = 11
LAWCARTA_DEFAULT_FONT_SIZE = 18
FONT_CONVERT_RATIO = LAWCARTA_DEFAULT_FONT_SIZE / WORD_DEFAULT_FONT_SIZE
LIVECARTA_DEFAULT_FONT_SIZE = 18
FONT_CONVERT_RATIO = LIVECARTA_DEFAULT_FONT_SIZE / WORD_DEFAULT_FONT_SIZE
font_correspondence_table = {
"Arial": "arial,helvetica,sans-serif",
"Comic Sans MS": "comic sans ms,cursive",