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
评论列表
文章目录