forked from LiveCarta/BookConverter
rewrite imports
This commit is contained in:
52
consumer.py
52
consumer.py
@@ -1,19 +1,17 @@
|
|||||||
import json
|
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from functools import partial
|
import json
|
||||||
from pathlib import Path
|
|
||||||
from threading import Thread, active_count
|
|
||||||
from threading import Event
|
|
||||||
|
|
||||||
import pika
|
import pika
|
||||||
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
|
from threading import Event
|
||||||
|
from functools import partial
|
||||||
|
from threading import Thread, active_count
|
||||||
|
|
||||||
from src.access import Access
|
from src.access import Access
|
||||||
from src.docx_converter.docx_solver import DocxBook
|
from src.docx_converter.docx_solver import DocxBook
|
||||||
from src.epub_converter.epub_solver import EpubBook
|
from src.epub_converter.epub_solver import EpubBook
|
||||||
|
|
||||||
|
|
||||||
def configure_file_logger(name, filename='logs/converter_log.log', filemode='w+',
|
def configure_file_logger(name, filename='logs/converter_log.log', filemode='w+',
|
||||||
logging_level=logging.INFO,
|
logging_level=logging.INFO,
|
||||||
logging_format='%(asctime)s - %(levelname)s - %(message)s'):
|
logging_format='%(asctime)s - %(levelname)s - %(message)s'):
|
||||||
@@ -27,9 +25,24 @@ def configure_file_logger(name, filename='logs/converter_log.log', filemode='w+'
|
|||||||
file_format = logging.Formatter(fmt=logging_format)
|
file_format = logging.Formatter(fmt=logging_format)
|
||||||
file_handler.setFormatter(file_format)
|
file_handler.setFormatter(file_format)
|
||||||
logger.setLevel(logging_level)
|
logger.setLevel(logging_level)
|
||||||
|
|
||||||
return logger
|
return logger
|
||||||
|
|
||||||
|
def local_convert_book(filename, locker):
|
||||||
|
logger = configure_file_logger('consumer')
|
||||||
|
logger.info(f'Start processing book-{filename}.')
|
||||||
|
|
||||||
|
folder_path = os.path.dirname(os.path.abspath("__file__"))
|
||||||
|
output_path = Path(os.path.join(folder_path, f'json/{filename}.json'))
|
||||||
|
try:
|
||||||
|
book = DocxBook(book_id=filename,
|
||||||
|
main_logger=logger,
|
||||||
|
libra_locker=locker)
|
||||||
|
book.test_conversion()
|
||||||
|
|
||||||
|
except Exception as exc:
|
||||||
|
raise exc
|
||||||
|
|
||||||
|
logger.info(f'Book-{filename} has been proceeded.')
|
||||||
|
|
||||||
def convert_book(book_type: [DocxBook, EpubBook], params: dict, logger, book_id):
|
def convert_book(book_type: [DocxBook, EpubBook], params: dict, logger, book_id):
|
||||||
logger.info(f'Start processing book-{book_id}.')
|
logger.info(f'Start processing book-{book_id}.')
|
||||||
@@ -79,25 +92,6 @@ def callback(ch, method, properties, body, logger, libra_locker):
|
|||||||
finally:
|
finally:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def local_convert_book(filename, locker):
|
|
||||||
logger = configure_file_logger('consumer', logging_format='%(asctime)s - %(levelname)s - %(message)s')
|
|
||||||
logger.info(f'Start processing book-{filename}.')
|
|
||||||
|
|
||||||
folder_path = os.path.dirname(os.path.abspath("__file__"))
|
|
||||||
output_path = Path(os.path.join(folder_path, f'json/{filename}.json'))
|
|
||||||
try:
|
|
||||||
book = DocxBook(book_id=filename,
|
|
||||||
main_logger=logger,
|
|
||||||
libra_locker=locker)
|
|
||||||
book.test_conversion()
|
|
||||||
|
|
||||||
except Exception as exc:
|
|
||||||
raise exc
|
|
||||||
|
|
||||||
logger.info(f'Book-{filename} has been proceeded.')
|
|
||||||
|
|
||||||
|
|
||||||
def local_run(books):
|
def local_run(books):
|
||||||
locker = Event()
|
locker = Event()
|
||||||
locker.set()
|
locker.set()
|
||||||
@@ -110,7 +104,6 @@ def local_run(books):
|
|||||||
|
|
||||||
[x.start() for x in threads]
|
[x.start() for x in threads]
|
||||||
|
|
||||||
|
|
||||||
def server_run():
|
def server_run():
|
||||||
logger = configure_file_logger('consumer')
|
logger = configure_file_logger('consumer')
|
||||||
|
|
||||||
@@ -151,4 +144,3 @@ def server_run():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
server_run()
|
server_run()
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
from subprocess import PIPE
|
from subprocess import PIPE
|
||||||
from threading import Event
|
from threading import Event
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
from src.docx_converter.html_docx_preprocessor import HTMLDocxPreprocessor
|
from src.docx_converter.html_docx_preprocessor import HTMLDocxPreprocessor
|
||||||
from src.docx_converter.libra_html2json_converter import LibraHTML2JSONConverter
|
from src.docx_converter.libra_html2json_converter import LibraHTML2JSONConverter
|
||||||
|
|
||||||
from src.book_solver import BookSolver
|
from src.book_solver import BookSolver
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import pathlib
|
|
||||||
import re
|
import re
|
||||||
from shutil import copyfile
|
import logging
|
||||||
|
import pathlib
|
||||||
from typing import List
|
from typing import List
|
||||||
|
from shutil import copyfile
|
||||||
|
|
||||||
from bs4 import BeautifulSoup, NavigableString, Tag
|
from bs4 import BeautifulSoup, NavigableString, Tag
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import logging
|
|
||||||
import re
|
import re
|
||||||
|
import logging
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
from src.livecarta_config import LiveCartaConfig
|
from src.livecarta_config import LiveCartaConfig
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import re
|
import re
|
||||||
|
import cssutils
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import cssutils
|
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from ebooklib import epub
|
from ebooklib import epub
|
||||||
|
from logging import CRITICAL
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
from premailer import transform
|
from premailer import transform
|
||||||
from itertools import takewhile
|
from itertools import takewhile
|
||||||
from logging import CRITICAL
|
|
||||||
|
|
||||||
from src.livecarta_config import LiveCartaConfig
|
from src.livecarta_config import LiveCartaConfig
|
||||||
from src.util.color_reader import str2hex
|
from src.util.color_reader import str2hex
|
||||||
|
|
||||||
|
|
||||||
cssutils.log.setLevel(CRITICAL)
|
cssutils.log.setLevel(CRITICAL)
|
||||||
|
|
||||||
sizes_pr = [-1, 0.5, 0.56, 0.63, 0.69, 0.75, 0.81, 0.88, 0.94, 1.0, 1.06, 1.13, 1.19, 1.25, 1.31, 1.38, 1.44, 1.5, 1.56,
|
sizes_pr = [-1, 0.5, 0.56, 0.63, 0.69, 0.75, 0.81, 0.88, 0.94, 1.0, 1.06, 1.13, 1.19, 1.25, 1.31, 1.38, 1.44, 1.5, 1.56,
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
import codecs
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from os.path import dirname, normpath, join
|
import json
|
||||||
|
import codecs
|
||||||
|
import logging
|
||||||
|
from itertools import chain
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Dict, Union, List
|
from typing import Dict, Union, List
|
||||||
from itertools import chain
|
from os.path import dirname, normpath, join
|
||||||
|
|
||||||
import ebooklib
|
import ebooklib
|
||||||
from bs4 import BeautifulSoup, Tag
|
|
||||||
from ebooklib import epub
|
from ebooklib import epub
|
||||||
|
from bs4 import BeautifulSoup, Tag
|
||||||
from ebooklib.epub import Link, Section
|
from ebooklib.epub import Link, Section
|
||||||
|
|
||||||
|
from src.util.helpers import BookLogger
|
||||||
|
from src.livecarta_config import LiveCartaConfig
|
||||||
from src.data_objects import ChapterItem, NavPoint
|
from src.data_objects import ChapterItem, NavPoint
|
||||||
|
from src.epub_converter.css_reader import build_css_content, convert_html_soup_with_css_style
|
||||||
from src.epub_converter.html_epub_preprocessor import unwrap_structural_tags, get_tags_between_chapter_marks, prepare_title_and_content, \
|
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
|
update_src_links_in_images, preprocess_footnotes
|
||||||
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:
|
class EpubConverter:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from src.epub_converter.epub_converter import EpubConverter
|
|
||||||
from src.book_solver import BookSolver
|
from src.book_solver import BookSolver
|
||||||
|
from src.epub_converter.epub_converter import EpubConverter
|
||||||
|
|
||||||
class EpubBook(BookSolver):
|
class EpubBook(BookSolver):
|
||||||
|
|
||||||
@@ -13,4 +13,3 @@ class EpubBook(BookSolver):
|
|||||||
content_dict = json_converter.convert_to_dict()
|
content_dict = json_converter.convert_to_dict()
|
||||||
self.status_wrapper.set_generating()
|
self.status_wrapper.set_generating()
|
||||||
return content_dict
|
return content_dict
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import pathlib
|
|
||||||
import re
|
import re
|
||||||
|
import pathlib
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
from bs4 import BeautifulSoup, NavigableString, Tag, Comment
|
from bs4 import BeautifulSoup, NavigableString, Tag, Comment
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import argparse
|
|
||||||
import os
|
import os
|
||||||
|
import argparse
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description="Utility for folders's clean up.")
|
parser = argparse.ArgumentParser(description="Utility for folders's clean up.")
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import argparse
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description="Utility for checking installed packages.")
|
parser = argparse.ArgumentParser(description="Utility for checking installed packages.")
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from webcolors import html4_hex_to_names, hex_to_rgb, rgb_to_name, rgb_percent_to_hex, rgb_to_hex, css3_names_to_hex
|
|
||||||
from colorsys import hls_to_rgb
|
from colorsys import hls_to_rgb
|
||||||
|
from webcolors import html4_hex_to_names, hex_to_rgb, rgb_to_name, rgb_percent_to_hex, rgb_to_hex, css3_names_to_hex
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def closest_colour_rgb(requested_color):
|
def closest_colour_rgb(requested_color):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class BookLogger:
|
class BookLogger:
|
||||||
@@ -8,7 +8,6 @@ class BookLogger:
|
|||||||
logging_format='%(asctime)s - %(levelname)s - %(message)s'):
|
logging_format='%(asctime)s - %(levelname)s - %(message)s'):
|
||||||
"""
|
"""
|
||||||
Method for Logger configuration. Logger will write to file.
|
Method for Logger configuration. Logger will write to file.
|
||||||
|
|
||||||
:param name: name of the Logger.
|
:param name: name of the Logger.
|
||||||
:param attr_name: name of attribute that will be added to self.
|
:param attr_name: name of attribute that will be added to self.
|
||||||
:param filename: name of the log file.
|
:param filename: name of the log file.
|
||||||
|
|||||||
Reference in New Issue
Block a user