aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--epub/epub.py2
-rw-r--r--export.py27
-rwxr-xr-xpyAggr3g470r.py8
3 files changed, 33 insertions, 4 deletions
diff --git a/epub/epub.py b/epub/epub.py
index 33193295..2c01b54a 100644
--- a/epub/epub.py
+++ b/epub/epub.py
@@ -240,7 +240,7 @@ class EpubBook:
def __writeItems(self):
for item in self.getAllItems():
- print item.id, item.destPath
+ #print item.id, item.destPath
if item.html:
fout = open(os.path.join(self.rootDir, 'OEBPS', item.destPath), 'w')
fout.write(item.html)
diff --git a/export.py b/export.py
index 9883eb65..cfe26e0d 100644
--- a/export.py
+++ b/export.py
@@ -157,4 +157,29 @@ def export_html(feeds):
content += htmlfooter
with open(name, "w") as f:
- f.write(content) \ No newline at end of file
+ f.write(content)
+
+def export_epub(feeds):
+ """
+ Export the articles given in parameter in ePub files.
+ """
+ from epub import ez_epub
+ for feed in feeds.values():
+ # creates folder for each stream
+ folder = utils.path + "/var/export/epub/" + \
+ utils.normalize_filename(feed.feed_title.strip().replace(':', '').lower())
+ try:
+ os.makedirs(folder)
+ except OSError:
+ # directories already exists (not a problem)
+ pass
+
+ for article in feed.articles.values():
+ name = article.article_date.strip().replace(' ', '_')
+ name = os.path.normpath(folder + "/" + name + ".epub")
+
+ section = ez_epub.Section()
+ section.title = article.article_title.decode('utf-8')
+ section.paragraphs = [utils.clear_string(article.article_description).decode('utf-8')]
+ ez_epub.makeBook(article.article_title.decode('utf-8'), [feed.feed_title.decode('utf-8')], [section], \
+ name, lang='en-US', cover=None) \ No newline at end of file
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py
index de8485a1..7ecae80b 100755
--- a/pyAggr3g470r.py
+++ b/pyAggr3g470r.py
@@ -281,7 +281,8 @@ class Root:
html += "<h1>Export articles</h1>\n\n"
html += """<form method=get action="/export/"><select name="export_method">\n"""
html += """\t<option value="export_webzine" selected='selected'>Simple Webzine</option>\n"""
- html += """\t<option value="export_html" selected='selected'>HTML</option>\n"""
+ html += """\t<option value="export_html">HTML</option>\n"""
+ html += """\t<option value="export_epub">ePub</option>\n"""
html += """\t<option value="export_txt">Text</option>\n"""
html += """</select>\n\t<input type="submit" value="Export">\n</form>\n"""
html += "<hr />\n\n"
@@ -1207,7 +1208,10 @@ class Root:
Export articles currently loaded from the SQLite database with
the appropriate function of the 'export' module.
"""
- getattr(export, export_method)(self.feeds)
+ try:
+ getattr(export, export_method)(self.feeds)
+ except Exception, e:
+ return self.error_page(e)
return self.management()
export.exposed = True
bgstack15