forked from LiveCarta/BookConverter
rewrite imports
This commit is contained in:
54
consumer.py
54
consumer.py
@@ -1,19 +1,17 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
from threading import Thread, active_count
|
||||
from threading import Event
|
||||
|
||||
import json
|
||||
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.docx_converter.docx_solver import DocxBook
|
||||
from src.epub_converter.epub_solver import EpubBook
|
||||
|
||||
|
||||
def configure_file_logger(name, filename='logs/converter_log.log', filemode='w+',
|
||||
logging_level=logging.INFO,
|
||||
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_handler.setFormatter(file_format)
|
||||
logger.setLevel(logging_level)
|
||||
|
||||
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):
|
||||
logger.info(f'Start processing book-{book_id}.')
|
||||
@@ -79,25 +92,6 @@ def callback(ch, method, properties, body, logger, libra_locker):
|
||||
finally:
|
||||
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):
|
||||
locker = Event()
|
||||
locker.set()
|
||||
@@ -110,7 +104,6 @@ def local_run(books):
|
||||
|
||||
[x.start() for x in threads]
|
||||
|
||||
|
||||
def server_run():
|
||||
logger = configure_file_logger('consumer')
|
||||
|
||||
@@ -150,5 +143,4 @@ def server_run():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
server_run()
|
||||
|
||||
server_run()
|
||||
@@ -1,14 +1,13 @@
|
||||
import logging
|
||||
import os
|
||||
import logging
|
||||
import pathlib
|
||||
import subprocess
|
||||
from subprocess import PIPE
|
||||
from threading import Event
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from src.docx_converter.html_docx_preprocessor import HTMLDocxPreprocessor
|
||||
from src.docx_converter.libra_html2json_converter import LibraHTML2JSONConverter
|
||||
|
||||
from src.book_solver import BookSolver
|
||||
|
||||
|
||||
@@ -155,4 +154,4 @@ if __name__ == "__main__":
|
||||
out_path = pathlib.Path(os.path.join(folder, 'json/ch13.json'))
|
||||
|
||||
book = DocxBook(html_path=file)
|
||||
book.convert_from_html()
|
||||
book.convert_from_html()
|
||||
@@ -1,9 +1,9 @@
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
from shutil import copyfile
|
||||
import logging
|
||||
import pathlib
|
||||
from typing import List
|
||||
from shutil import copyfile
|
||||
|
||||
from bs4 import BeautifulSoup, NavigableString, Tag
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import logging
|
||||
import re
|
||||
import logging
|
||||
from copy import copy
|
||||
|
||||
from src.livecarta_config import LiveCartaConfig
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import re
|
||||
import cssutils
|
||||
from typing import List
|
||||
|
||||
import cssutils
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from ebooklib import epub
|
||||
from logging import CRITICAL
|
||||
from bs4 import BeautifulSoup
|
||||
from premailer import transform
|
||||
from itertools import takewhile
|
||||
from logging import CRITICAL
|
||||
|
||||
from src.livecarta_config import LiveCartaConfig
|
||||
from src.util.color_reader import str2hex
|
||||
|
||||
|
||||
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,
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
import codecs
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from os.path import dirname, normpath, join
|
||||
import json
|
||||
import codecs
|
||||
import logging
|
||||
from itertools import chain
|
||||
from collections import defaultdict
|
||||
from typing import Dict, Union, List
|
||||
from itertools import chain
|
||||
from os.path import dirname, normpath, join
|
||||
|
||||
import ebooklib
|
||||
from bs4 import BeautifulSoup, Tag
|
||||
from ebooklib import epub
|
||||
from bs4 import BeautifulSoup, Tag
|
||||
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.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, \
|
||||
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:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from src.epub_converter.epub_converter import EpubConverter
|
||||
from src.book_solver import BookSolver
|
||||
from src.epub_converter.epub_converter import EpubConverter
|
||||
|
||||
class EpubBook(BookSolver):
|
||||
|
||||
@@ -12,5 +12,4 @@ class EpubBook(BookSolver):
|
||||
json_converter = EpubConverter(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
|
||||
|
||||
return content_dict
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import pathlib
|
||||
from typing import Tuple
|
||||
|
||||
from bs4 import BeautifulSoup, NavigableString, Tag, Comment
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import argparse
|
||||
import os
|
||||
|
||||
import argparse
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description="Utility for folders's clean up.")
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description="Utility for checking installed packages.")
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
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 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):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import logging
|
||||
import os
|
||||
import logging
|
||||
|
||||
|
||||
class BookLogger:
|
||||
@@ -8,7 +8,6 @@ class BookLogger:
|
||||
logging_format='%(asctime)s - %(levelname)s - %(message)s'):
|
||||
"""
|
||||
Method for Logger configuration. Logger will write to file.
|
||||
|
||||
:param name: name of the Logger.
|
||||
:param attr_name: name of attribute that will be added to self.
|
||||
:param filename: name of the log file.
|
||||
|
||||
Reference in New Issue
Block a user