예제 #1
0
 def add_index_html(self, src, title):
     Path.copy(src, EpubPath.html_path)
     filename = Path.get_filename(src)
     new_src = u'html/' + filename
     resource_id = self.opf.add_html(new_src)
     self.toc.add_item(resource_id, new_src, title)
     return
예제 #2
0
 def add_index_html(self, src, title):
     Path.copy(src, EpubPath.html_path)
     filename = Path.get_filename(src)
     new_src = u'html/' + filename
     resource_id = self.opf.add_html(new_src)
     self.toc.add_item(resource_id, new_src, title)
     return
예제 #3
0
 def create_chapter(self, src, title):
     Path.copy(src, EpubPath.html_path)
     filename = Path.get_filename(src)
     new_src = u'html/' + filename
     resource_id = self.opf.add_title_page_html(new_src)
     self.directory.create_chapter(new_src, title)
     self.toc.create_chapter(resource_id, new_src, title)
     return
예제 #4
0
 def create_chapter(self, src, title):
     Path.copy(src, EpubPath.html_path)
     filename = Path.get_filename(src)
     new_src = u'html/' + filename
     resource_id = self.opf.add_title_page_html(new_src)
     self.directory.create_chapter(new_src, title)
     self.toc.create_chapter(resource_id, new_src, title)
     return
예제 #5
0
 def create_single_html_book(self, book_package):
     title = book_package.get_title()
     if not title:
         # 电子书题目为空时自动跳过
         # 否则会发生『rm -rf / 』的惨剧
         return
     Path.reset_path()
     Path.chdir(Path.result_path)
     Path.rmdir(u'./' + title)
     Path.mkdir(u'./' + title)
     Path.chdir(u'./' + title)
     page = []
     for book in book_package.book_list:
         page += book.page_list
     content = u' \r\n '.join([Match.html_body(x.content) for x in page]).replace(u'../images/', u'./images/')
     with open(TemplateConfig.content_base_uri) as html:
         content = html.read().format(title=title, body=content).replace(u'../style/', u'./')
     with open(title + u'.html', 'w') as html:
         html.write(content)
     Path.copy(Path.html_pool_path + u'/../{}/OEBPS/images'.format(title), u'./images')
     Path.copy(Path.www_css + u'/customer.css', u'./customer.css')
     Path.copy(Path.www_css + u'/markdown.css', u'./markdown.css')
     Path.copy(Path.www_css + u'/normalize.css', u'./normalize.css')
     Path.reset_path()
     return
예제 #6
0
def reloadtocatch():
    rootdir = "/Volumes/MacintoshHD/TC/todo"  # 指明被遍历的文件夹
    filelist = os.listdir(rootdir)
    ff = open('TGB_List.txt', 'w')
    for file in filelist:
        print file
        # if file.startswith('TGB'):
        article_id = (str(file).split('_')[-1]).strip(')')
        print article_id
        # tagrId = u"http://www.taoguba.com.cn/Article/{}/0\n".format(article_id)
        tagrId = u"https://www.huxiu.com/{}\n".format(article_id)
        ff.write(tagrId)

    # 图片文件夹
    rootdir = "/Volumes/MacintoshHD/TC/todo"  # 指明被遍历的文件夹
    picdir = "/Volumes/MacintoshHD/TC/picture"
    filelist = os.listdir(rootdir)
    ff = open('TGB_List.txt', 'w')
    for parent, dirnames, filenames in os.walk(
            rootdir):  # 三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字
        # for dirname in dirnames:  # 输出文件夹信息
        #     # print "parent is: " + parent
        #     print  "dirname is: " + dirname

        for filename in filenames:  # 输出文件信息
            print "parent is :" + parent
            print "filename is:" + filename
            print "the full name of the file is:" + os.path.join(
                parent, filename)  # 输出文件路径信息

            if filename.endswith('jpg'):
                Path.copy(os.path.join(parent, filename), picdir)

    # for parent, dirnames, filenames in os.walk(rootdir):  # 三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字
    #     for dirname in dirnames:  # 输出文件夹信息
    #     #     # print "parent is: " + parent
    #         print  "dirname is: " + dirname
    #
    #     # for filename in filenames:  # 输出文件信息
    #     #     print "parent is :" + parent
    #     #     print "filename is:" + filename
    #     #     print "the full name of the file is:" + os.path.join(parent, filename)  # 输出文件路径信息
    ff.close()
예제 #7
0
파일: download.py 프로젝트: bindx/EE-Book
    def download_button_clicked(self):
        tags = str(self.custom_tags.text())

        # url_id = self.recipes.model.data(1, QtCore.Qt.UserRole)    # TODO: 获得选中的recipes
        url_id = str(self.row_clicked(self.recipes.currentIndex()))

        if url_id == 'None':
            QtGui.QMessageBox.information(self, u"Error", u"选择需要爬取的网站!")
            return

        readlist_content = self.plainTextEdit.toPlainText()

        if readlist_content == '':
            QtGui.QMessageBox.information(self, u"Error", u"请在文本框中输入网址")
            return

        read_list_path = Path.read_list_path

        readList_file = open(read_list_path, 'w')
        readList_file.write(readlist_content)

        readList_file.close()

        game = EEBook(recipe_kind=url_id)

        progress_dlg = QProgressDialog(self)        # TODO: 设置大小, 区域
        progress_dlg.setWindowModality(Qt.WindowModal)
        progress_dlg.setMinimumDuration(5)
        progress_dlg.setWindowTitle(u"请等待")
        progress_dlg.setLabelText(u"制作中...请稍候")
        progress_dlg.setCancelButtonText(u"取消")
        progress_dlg.resize(350, 250)
        progress_dlg.show()
        progress_dlg.setRange(0, 20)

        for i in range(0, 15):
            progress_dlg.setValue(i)
            QThread.msleep(100)

        for i in range(15, 20):
            progress_dlg.setValue(i)
            QThread.msleep(100)
            if progress_dlg.wasCanceled():
                QtGui.QMessageBox.information(self, u"Error", u"电子书制作失败, 请重新操作")
                return

            try:
                filename = game.begin()      # TODO: 一次只能生成一本书
            except TypeError:
                QtGui.QMessageBox.information(self, u"Error", u"第一次使用请登录")
                progress_dlg.close()
                return
            progress_dlg.close()

            info_filename = ','.join(filename)
            QtGui.QMessageBox.information(self, u"info", u"电子书"+str(info_filename)+u"制作成功")

            for item in filename:
                file_path = EPUBSTOR_DIR + '/' + item
                Path.copy(str(file_path+'.epub'), LIBRARY_DIR)
                file_name = os.path.basename(str(file_path))
                book_id = file_name.split('.epub')[0]

                Path.mkdir(LIBRARY_DIR + book_id)
                shutil.move(LIBRARY_DIR+book_id+'.epub', LIBRARY_DIR+book_id)

                book = Book(str(book_id))
                book.date = time.strftime(ISOTIMEFORMAT, time.localtime())
                book.tags += tags.replace(' ', '')
                book.tags += ','+str(self.now_url)
                if self.add_title_tag.isChecked():
                    book.tags += ','+str(book.title)
                insert_library(book)
            return
예제 #8
0
 def add_cover_image(self, src):
     Path.copy(src, EpubPath.image_path)
     filename = Path.get_filename(src)
     new_src = u'images/' + filename
     resource_id = self.opf.add_cover_image(new_src)
     return
예제 #9
0
 def add_css(self, src):
     Path.copy(src, EpubPath.style_path)
     filename = Path.get_filename(src)
     new_src = u'style/' + filename
     resource_id = self.opf.add_css(new_src)
     return
예제 #10
0
    def download_button_clicked(self):
        tags = str(self.custom_tags.text())

        # url_id = self.recipes.model.data(1, QtCore.Qt.UserRole)    # TODO: 获得选中的recipes
        url_id = str(self.row_clicked(self.recipes.currentIndex()))

        if url_id == 'None':
            QtGui.QMessageBox.information(self, u"Error", u"选择需要爬取的网站!")
            return

        readlist_content = self.plainTextEdit.toPlainText()

        if readlist_content == '':
            QtGui.QMessageBox.information(self, u"Error", u"请在文本框中输入网址")
            return

        read_list_path = Path.read_list_path

        readList_file = open(read_list_path, 'w')
        readList_file.write(readlist_content)

        readList_file.close()

        game = EEBook(recipe_kind=url_id)

        progress_dlg = QProgressDialog(self)  # TODO: 设置大小, 区域
        progress_dlg.setWindowModality(Qt.WindowModal)
        progress_dlg.setMinimumDuration(5)
        progress_dlg.setWindowTitle(u"请等待")
        progress_dlg.setLabelText(u"制作中...请稍候")
        progress_dlg.setCancelButtonText(u"取消")
        progress_dlg.resize(350, 250)
        progress_dlg.show()
        progress_dlg.setRange(0, 20)

        for i in range(0, 15):
            progress_dlg.setValue(i)
            QThread.msleep(100)

        for i in range(15, 20):
            progress_dlg.setValue(i)
            QThread.msleep(100)
            if progress_dlg.wasCanceled():
                QtGui.QMessageBox.information(self, u"Error",
                                              u"电子书制作失败, 请重新操作")
                return

            try:
                filename = game.begin()  # TODO: 一次只能生成一本书
            except TypeError:
                QtGui.QMessageBox.information(self, u"Error", u"第一次使用请登录")
                progress_dlg.close()
                return
            progress_dlg.close()

            info_filename = ','.join(filename)
            QtGui.QMessageBox.information(
                self, u"info", u"电子书" + str(info_filename) + u"制作成功")

            for item in filename:
                file_path = EPUBSTOR_DIR + '/' + item
                Path.copy(str(file_path + '.epub'), LIBRARY_DIR)
                file_name = os.path.basename(str(file_path))
                book_id = file_name.split('.epub')[0]

                Path.mkdir(LIBRARY_DIR + book_id)
                shutil.move(LIBRARY_DIR + book_id + '.epub',
                            LIBRARY_DIR + book_id)

                book = Book(str(book_id))
                book.date = time.strftime(ISOTIMEFORMAT, time.localtime())
                book.tags += tags.replace(' ', '')
                book.tags += ',' + str(self.now_url)
                if self.add_title_tag.isChecked():
                    book.tags += ',' + str(book.title)
                insert_library(book)
            return
예제 #11
0
 def add_cover_image(self, src):
     Path.copy(src, EpubPath.image_path)
     filename = Path.get_filename(src)
     new_src = u'images/' + filename
     resource_id = self.opf.add_cover_image(new_src)
     return
예제 #12
0
 def add_css(self, src):
     Path.copy(src, EpubPath.style_path)
     filename = Path.get_filename(src)
     new_src = u'style/' + filename
     resource_id = self.opf.add_css(new_src)
     return
예제 #13
0
 def add_duokan_ext():
     Path.copy(EpubConfig.duokan_container_uri, EpubPath.meta_inf_path)
     return
예제 #14
0
 def add_container():
     Path.copy(EpubConfig.container_uri, EpubPath.meta_inf_path)
     return