aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2011-10-25 09:35:57 +0200
committercedricbonhomme <devnull@localhost>2011-10-25 09:35:57 +0200
commitbf515daf542968086440bd092b38a241b59ae580 (patch)
tree33cb58250771d6b5a1af11d9f2738d6b2b61fff3
parentAdded .hgignire file. (diff)
downloadnewspipe-bf515daf542968086440bd092b38a241b59ae580.tar.gz
newspipe-bf515daf542968086440bd092b38a241b59ae580.tar.bz2
newspipe-bf515daf542968086440bd092b38a241b59ae580.zip
Updated .hgignore. Added a function to export the articles database to pdf files.
-rw-r--r--.hgignore1
-rw-r--r--export.py34
-rwxr-xr-xpyAggr3g470r.py1
3 files changed, 35 insertions, 1 deletions
diff --git a/.hgignore b/.hgignore
index e41301b5..d79d7978 100644
--- a/.hgignore
+++ b/.hgignore
@@ -16,3 +16,4 @@ CherryPy log files:
cfg/pyAggr3g470r.cfg
+var/export/*
diff --git a/export.py b/export.py
index cfe26e0d..5db4e290 100644
--- a/export.py
+++ b/export.py
@@ -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
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py
index 7ecae80b..0a8ba4a1 100755
--- a/pyAggr3g470r.py
+++ b/pyAggr3g470r.py
@@ -283,6 +283,7 @@ class Root:
html += """\t<option value="export_webzine" selected='selected'>Simple Webzine</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_pdf">PDF</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"
bgstack15