diff options
-rw-r--r-- | .hgignore | 1 | ||||
-rw-r--r-- | export.py | 34 | ||||
-rwxr-xr-x | pyAggr3g470r.py | 1 |
3 files changed, 35 insertions, 1 deletions
@@ -16,3 +16,4 @@ CherryPy log files: cfg/pyAggr3g470r.cfg +var/export/* @@ -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" |