diff options
author | cedricbonhomme <devnull@localhost> | 2011-10-25 09:35:57 +0200 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2011-10-25 09:35:57 +0200 |
commit | bf515daf542968086440bd092b38a241b59ae580 (patch) | |
tree | 33cb58250771d6b5a1af11d9f2738d6b2b61fff3 /export.py | |
parent | Added .hgignire file. (diff) | |
download | newspipe-bf515daf542968086440bd092b38a241b59ae580.tar.gz newspipe-bf515daf542968086440bd092b38a241b59ae580.tar.bz2 newspipe-bf515daf542968086440bd092b38a241b59ae580.zip |
Updated .hgignore. Added a function to export the articles database to pdf files.
Diffstat (limited to 'export.py')
-rw-r--r-- | export.py | 34 |
1 files changed, 33 insertions, 1 deletions
@@ -182,4 +182,36 @@ def export_epub(feeds): 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 + name, lang='en-US', cover=None) + +def export_pdf(feeds): + """ + """ + from xhtml2pdf import pisa + import cStringIO as StringIO + for feed in feeds.values(): + # creates folder for each stream + folder = utils.path + "/var/export/pdf/" + \ + 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 + ".pdf") + + content = htmlheader + content += '\n<div style="width: 50%; overflow:hidden; text-align: justify; margin:0 auto">\n' + content += """<h1><a href="%s">%s</a></h1><br />""" % \ + (article.article_link, article.article_title) + content += article.article_description + content += "</div>\n<hr />\n" + content += htmlfooter + + try: + pdf = pisa.CreatePDF(StringIO.StringIO(content), file(name, "wb")) + except: + pass
\ No newline at end of file |