diff options
author | cedricbonhomme <devnull@localhost> | 2010-11-23 22:13:32 +0100 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-11-23 22:13:32 +0100 |
commit | 0ce90a043eef532a71952e6aac43e6be6affc0f0 (patch) | |
tree | 1adaa7e3ff72891223705a0bafa978f74d3d3984 /epub/ez_epub.py | |
parent | Improvement of the search results (ToolTips, display). (diff) | |
download | newspipe-0ce90a043eef532a71952e6aac43e6be6affc0f0.tar.gz newspipe-0ce90a043eef532a71952e6aac43e6be6affc0f0.tar.bz2 newspipe-0ce90a043eef532a71952e6aac43e6be6affc0f0.zip |
Added import to EPUB function.
Diffstat (limited to 'epub/ez_epub.py')
-rw-r--r-- | epub/ez_epub.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/epub/ez_epub.py b/epub/ez_epub.py new file mode 100644 index 00000000..afd2dbff --- /dev/null +++ b/epub/ez_epub.py @@ -0,0 +1,38 @@ +#! /usr/local/bin/python
+#-*- coding: utf-8 -*-
+
+import epub
+from genshi.template import TemplateLoader
+
+class Section:
+
+ def __init__(self):
+ self.title = ''
+ self.paragraphs = []
+ self.tocDepth = 1
+
+def makeBook(title, authors, sections, outputDir, lang='en-US', cover=None):
+ book = epub.EpubBook()
+ book.setLang(lang)
+ book.setTitle(title)
+ for author in authors:
+ book.addCreator(author)
+ #book.addTitlePage()
+ #book.addTocPage()
+ #if cover:
+ #book.addCover(cover)
+
+ loader = TemplateLoader('./epub/templates')
+ tmpl = loader.load('ez-section.html')
+
+ for i, section in enumerate(sections):
+ stream = tmpl.generate(section = section)
+ html = stream.render('xhtml', doctype='xhtml11', drop_xml_decl=False)
+ item = book.addHtml('', 's%d.html' % (i + 1), html)
+ book.addSpineItem(item)
+ book.addTocMapNode(item.destPath, section.title, section.tocDepth)
+
+ outputFile = outputDir + 'article.epub'
+ book.createBook(outputDir)
+ book.createArchive(outputDir, outputFile)
+ #book.checkEpub('epubcheck-1.0.5.jar', outputFile)
\ No newline at end of file |