Пример #1
0
    def generic_visit(self, node, *args, **kwargs) -> str:
        """Called if no explicit visitor function exists for a node."""
        if node is None:
            return ''

        content = []
        try:
            for child in node.contents:
                value = self.visit(child, *args, **kwargs)
                content.append(value)
        except TypeError as e:
            logs.error(e)
        return ''.join(content)
Пример #2
0
def download_url(url_path: str, file_path: str):
    headers = {
        'Accept': '*/*',
        'User-Agent': 'curl/7.64.1',
    }
    req = requests.get(url_path, headers=headers, stream=True)
    if req.status_code != 200:
        logs.error(f'Cannot make request. Result: {req.status_code:d}')
        exit(1)

    with open(file_path, 'wb') as file_out:
        req.raw.decode_content = True
        shutil.copyfileobj(req.raw, file_out)
Пример #3
0
    def ebook_generate_content(self, url_path):
        content = self.download_content(url_path)
        bs = BeautifulSoup(content, 'html.parser')

        chapter_metadata = self.config.get('metadata', True)
        title_strip = self.config.get('title_prefix_trim', '')
        try:
            extractor = etr.create_extractor(url_path, bs)
            extractor.cleanup()
            transformer = etr.create_transformer(url_path,
                                                 extractor.get_content(),
                                                 self.output_dir)
            transformer.transform()
            self.book_maker.render_chapter(extractor,
                                           transformer,
                                           url_path,
                                           self._get_saved_file_name(url_path),
                                           metadata=chapter_metadata,
                                           title_strip=title_strip)
        except etr.ContentNotFoundError as e:
            logs.error(e, url_path)
Пример #4
0
def generate(args):
    try:
        Colusa.generate_book(args.input)
    except ConfigurationError as e:
        logs.error(e)
Пример #5
0
def init(args):
    try:
        Colusa.generate_new_configuration(args.output)
    except ConfigurationError as e:
        logs.error(e)