diff options
author | cedricbonhomme <devnull@localhost> | 2012-05-01 15:03:39 +0200 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2012-05-01 15:03:39 +0200 |
commit | decbb1f28d9a448aacc50d64bede603cf4e1261d (patch) | |
tree | 0c22e8616fddd7b97a3aeccfcfe2a09d2701b6cf | |
parent | Export to text files OK. (diff) | |
download | newspipe-decbb1f28d9a448aacc50d64bede603cf4e1261d.tar.gz newspipe-decbb1f28d9a448aacc50d64bede603cf4e1261d.tar.bz2 newspipe-decbb1f28d9a448aacc50d64bede603cf4e1261d.zip |
Export to EPUB OK.
-rw-r--r-- | source/export.py | 69 | ||||
-rwxr-xr-x | source/pyAggr3g470r.py | 4 |
2 files changed, 36 insertions, 37 deletions
diff --git a/source/export.py b/source/export.py index bd98cc79..62e244b9 100644 --- a/source/export.py +++ b/source/export.py @@ -109,49 +109,50 @@ def export_txt(mongo_db): """ feeds = mongo_db.get_all_feeds() for feed in feeds: - # creates folder for each stream - folder = conf.path + "/var/export/txt/" + \ - utils.normalize_filename(feed["feed_title"].strip().replace(':', '').lower().encode('utf-8')) - try: - os.makedirs(folder) - except OSError: - # directories already exists (not a problem) - pass + # creates folder for each stream + folder = conf.path + "/var/export/txt/" + \ + utils.normalize_filename(feed["feed_title"].strip().replace(':', '').lower().encode('utf-8')) + try: + os.makedirs(folder) + except OSError: + # directories already exists (not a problem) + pass - for article in mongo_db.get_articles_from_collection(feed["feed_id"]): - name = article["article_date"].ctime().strip().replace(' ', '_') - name = os.path.normpath(folder + "/" + name + ".txt") + for article in mongo_db.get_articles_from_collection(feed["feed_id"]): + name = article["article_date"].ctime().strip().replace(' ', '_') + name = os.path.normpath(folder + "/" + name + ".txt") - content = "Title: " + article["article_title"] + "\n\n\n" - content += utils.clear_string(article["article_content"]) + content = "Title: " + article["article_title"] + "\n\n\n" + content += utils.clear_string(article["article_content"]) - with open(name, "w") as f: - f.write(content.encode('utf-8')) + with open(name, "w") as f: + f.write(content.encode('utf-8')) -def export_epub(feeds): +def export_epub(mongo_db): """ 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") + feeds = mongo_db.get_all_feeds() + for feed in feeds: + # creates folder for each stream + folder = conf.path + "/var/export/epub/" + \ + utils.normalize_filename(feed["feed_title"].strip().replace(':', '').lower().encode('utf-8')) + try: + os.makedirs(folder) + except OSError: + # directories already exists (not a problem) + pass - 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) + for article in mongo_db.get_articles_from_collection(feed["feed_id"]): + name = article["article_date"].ctime().strip().replace(' ', '_') + name = os.path.normpath(folder + "/" + name + ".epub") + + section = ez_epub.Section() + section.title = article["article_title"] + section.paragraphs = [utils.clear_string(article["article_content"])] + ez_epub.makeBook(article["article_title"], [feed["feed_title"]], [section], \ + name, lang='en-US', cover=None) def export_pdf(feeds): """ diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py index a135debd..55c37127 100755 --- a/source/pyAggr3g470r.py +++ b/source/pyAggr3g470r.py @@ -1218,12 +1218,10 @@ class Root: if __name__ == '__main__': # Point of entry in execution mode - print "Launching pyAggr3g470r..." - root = Root() root.favicon_ico = cherrypy.tools.staticfile.handler(filename=os.path.join(conf.path + "/img/favicon.png")) cherrypy.config.update({ 'server.socket_port': 12556, 'server.socket_host': "0.0.0.0"}) cherrypy.config.update({'error_page.404': error_page_404}) _cp_config = {'request.error_response': handle_error} - cherrypy.quickstart(root, "/" ,config=conf.path + "/cfg/cherrypy.cfg") + cherrypy.quickstart(root, "/" ,config=conf.path + "/cfg/cherrypy.cfg")
\ No newline at end of file |