From 4a6706c867582b44f0fa8f6a8ea0223bf9376342 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Tue, 25 Oct 2011 00:05:21 +0200 Subject: It is now possible to export all the database in the ePub format. --- epub/epub.py | 2 +- export.py | 27 ++++++++++++++++++++++++++- pyAggr3g470r.py | 8 ++++++-- 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 += "

Export articles

\n\n" html += """
\n\t\n
\n""" html += "
\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 -- cgit