diff options
author | cedricbonhomme <devnull@localhost> | 2011-10-25 00:05:21 +0200 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2011-10-25 00:05:21 +0200 |
commit | 4a6706c867582b44f0fa8f6a8ea0223bf9376342 (patch) | |
tree | bb4a016a11d59b8fed2dc9fa23703900907b847d /export.py | |
parent | Refactored export functions properly. The appropriate export function of the ... (diff) | |
download | newspipe-4a6706c867582b44f0fa8f6a8ea0223bf9376342.tar.gz newspipe-4a6706c867582b44f0fa8f6a8ea0223bf9376342.tar.bz2 newspipe-4a6706c867582b44f0fa8f6a8ea0223bf9376342.zip |
It is now possible to export all the database in the ePub format.
Diffstat (limited to 'export.py')
-rw-r--r-- | export.py | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -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 |