app.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:MercrediFiction 作者: Meewan 项目源码 文件源码
def create_epub():
    toots, _, _ = get_toots()
    accounts, _, _ = get_accounts()
    book = epub.EpubBook()

    # add metadata
    book.set_identifier('mercredi-fiction')
    book.set_title('#MercrediFiction')
    book.set_language('fr')

    for account in accounts:
        book.add_author(account.username)

    chapter = epub.EpubHtml(title='Toutes les histoires',
                            file_name='index.xhtml',
                            lang='fr')
    chapter.content = render_template('epub.html', toots=toots)
    book.add_item(chapter)

    book.toc = (epub.Link('index.xhtml', 'Toutes les histoires', 'histoires'),)

    book.add_item(epub.EpubNcx())
    book.add_item(epub.EpubNav())

    book.spine = ['nav', chapter]

    clean_epub_directory()
    epub_name = str(time()) + '.epub'
    epub_path = path.join(config.EPUB_DIRECTORY, epub_name)
    epub.write_epub(epub_path, book)
    response = send_from_directory(config.EPUB_DIRECTORY, epub_name)
    response.headers['Content-Disposition'] = 'attachment;filename="mercredifiction.epub"'
    return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号