コード例 #1
0
    def create(self):
        self.image_container.set_save_path(Path.image_pool_path)
        self.image_container.start_download()
        title = "_".join([book.property.epub.title for book in self.book_list])
        title = title.strip()
        Path.chdir(Path.base_path + u"/知乎电子书临时资源库/")
        epub = Book(title, 27149527)
        html_tmp_path = Path.html_pool_path + "/"
        image_tmp_path = Path.image_pool_path + "/"
        for book in self.book_list:
            page = book.page_list[0]
            with open(html_tmp_path + page.filename, "w") as html:
                html.write(page.content)
            epub.createChapter(html_tmp_path + page.filename, ExtraTools.get_time(), page.title)

            for page in book.page_list[1:]:
                with open(html_tmp_path + page.filename, "w") as html:
                    html.write(page.content)
                epub.addHtml(html_tmp_path + page.filename, page.title)
        for image in self.book["image_list"]:
            epub.addImg(image_tmp_path + image["filename"])
        epub.addLanguage("zh-cn")
        epub.addCreator("ZhihuHelp1.7.0")
        epub.addDesc(u"该电子书由知乎助手生成,知乎助手是姚泽源为知友制作的仅供个人使用的简易电子书制作工具,源代码遵循WTFPL,希望大家能认真领会该协议的真谛,为飞面事业做出自己的贡献 XD")
        epub.addRight("CC")
        epub.addPublisher("ZhihuHelp")
        Debug.logger.debug(u"当前目录为")
        Path.pwd()
        epub.addCss(Path.base_path + u"/epubResource/markdown.css")
        epub.addCss(Path.base_path + u"/epubResource/front.css")
        epub.buildingEpub()
        return
コード例 #2
0
 def start(self):
     raw_book_list = self.init_book_data()
     book_list = [self.translate_book_into_html(book) for book in raw_book_list]
     for book in book_list:
         BaseClass.change_dir(self.base_path)
         BaseClass.change_dir(self.base_path + u'/知乎电子书临时资源库')
         epub = Book(book['info']['title'], 27149527)
         book.start_download_image()
         for page in book['page_list']:
             with open(self.base_path + u'/知乎电子书临时资源库' + page['filename'], 'w') as html:
                 html.write(page['content'])
             epub.addHtml(self.base_path + u'/知乎电子书临时资源库' + page['filename'], page['title'])
         for filename in book['image_list']:
             epub.addImg(self.base_path + u'/知乎电子书临时资源库/知乎图片池' + filename)
             book.addLanguage('zh-cn')
             epub.addCreator('ZhihuHelp1.7.0')
             epub.addDesc(u'该电子书由知乎助手生成,知乎助手是姚泽源为知友制作的仅供个人使用的简易电子书制作工具,源代码遵循WTFPL,希望大家能认真领会该协议的真谛,为飞面事业做出自己的贡献 XD')
             epub.addRight('CC')
             epub.addPublisher('ZhihuHelp')
             epub.addCss(u'../../../epubResource/markdownStyle.css')
             epub.addCss(u'../../../epubResource/userDefine.css')
             epub.buildingEpub()
     return
コード例 #3
0
 def create(self):
     self.image_container.set_save_path(Path.image_pool_path)
     self.image_container.start_download()
     title = '_'.join([book.epub.title for book in self.book_list])
     title = title.strip()[:128] # 避开window文件名长度限制
     title = ExtraTools.fix_filename(title) # 移除特殊字符
     if not title:
         # 电子书题目为空时自动跳过
         # 否则会发生『rm -rf / 』的惨剧。。。
         return
     Path.chdir(Path.base_path + u'/知乎电子书临时资源库/')
     epub = Book(title, 27149527)
     html_tmp_path = Path.html_pool_path + '/'
     image_tmp_path = Path.image_pool_path + '/'
     for book in self.book_list:
         page = book.page_list[0]
         with open(html_tmp_path + page.filename, 'w') as html:
             html.write(page.content)
         #epub.createChapter(html_tmp_path + page.filename, ExtraTools.get_time(), page.title)
         epub.addInfoPage(html_tmp_path + page.filename, page.title)
         for page in book.page_list[1:]:
             with open(html_tmp_path + page.filename, 'w') as html:
                 html.write(page.content)
             epub.addHtml(html_tmp_path + page.filename, page.title)
     for image in self.book.image_list:
         epub.addImg(image_tmp_path + image['filename'])
     epub.addLanguage('zh-cn')
     epub.addCreator('ZhihuHelp1.7.0')
     epub.addDesc(u'该电子书由知乎助手生成,知乎助手是姚泽源为知友制作的仅供个人使用的简易电子书制作工具,源代码遵循WTFPL,希望大家能认真领会该协议的真谛,为飞面事业做出自己的贡献 XD')
     epub.addRight('CC')
     epub.addPublisher('ZhihuHelp')
     epub.addCss(Path.base_path + u'/www/css/markdown.css')
     epub.addCss(Path.base_path + u'/www/css/front.css')
     epub.buildingEpub()
     Path.reset_path()
     return