diff options
author | cedricbonhomme <devnull@localhost> | 2010-11-23 22:13:32 +0100 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-11-23 22:13:32 +0100 |
commit | 0ce90a043eef532a71952e6aac43e6be6affc0f0 (patch) | |
tree | 1adaa7e3ff72891223705a0bafa978f74d3d3984 /pyAggr3g470r.py | |
parent | Improvement of the search results (ToolTips, display). (diff) | |
download | newspipe-0ce90a043eef532a71952e6aac43e6be6affc0f0.tar.gz newspipe-0ce90a043eef532a71952e6aac43e6be6affc0f0.tar.bz2 newspipe-0ce90a043eef532a71952e6aac43e6be6affc0f0.zip |
Added import to EPUB function.
Diffstat (limited to 'pyAggr3g470r.py')
-rwxr-xr-x | pyAggr3g470r.py | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 6174945f..610b69b4 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -491,6 +491,8 @@ class Root: (article[6], article[6]) html += """<br />\n<a href="/plain_text/%s:%s">Plain text</a>\n""" % \ (feed_id, article_id) + html += """\n<a href="/epub/%s:%s">Export to epub</a>\n""" % \ + (feed_id, article_id) html += """<br />\n<a href="%s">Complete story</a>\n<br />\n""" % \ (article[3].encode('utf-8'),) # Share this article: @@ -1100,6 +1102,10 @@ class Root: drop_base.exposed = True + # + # Export functions + # + def export(self, export_method): """ Export articles stored in the SQLite database in text @@ -1150,6 +1156,7 @@ class Root: content += article[4].encode('utf-8') content += "</div>\n<hr />\n" content += htmlfooter + # Export for dokuwiki # example: http://wiki.cedricbonhomme.org/doku.php/news-archives elif export_method == "export_dokuwiki": @@ -1160,12 +1167,14 @@ class Root: (article[3].encode('utf-8'), article[2].encode('utf-8')) content += article[4].encode('utf-8') content += '</div>\n<hr />Generated with <a href="http://bitbucket.org/cedricbonhomme/pyaggr3g470r/">pyAggr3g470r</a>\n</html>' + # Export all articles in RSS format elif export_method == "export_RSS": content += """<item>\n<title>%s</title>\n<link>%s</link>\n""" % (article[2], article[3]) content += """<pubDate>%s</pubDate>\n""" % (str(article[1]),) content += """<description><![CDATA[%s]]></description>""" % (article[4],) content += "</item>\n" + # Export all articles in raw text elif export_method == "export_TXT": content = "Title: " + article[2].encode('utf-8') + "\n\n\n" @@ -1184,6 +1193,41 @@ class Root: export.exposed = True + def epub(self, param): + """ + Export article(s) to epub. + """ + try: + from epub import ez_epub + except Exception, e: + return self.error_page(e) + try: + feed_id, article_id = param.split(':') + except: + return self.error_page("Bad URL") + try: + articles_list = self.articles[feed_id] + except KeyError: + return self.error_page("This feed do not exists.") + try: + folder = utils.path + "/var/export/epub/" + os.makedirs(folder) + except OSError: + return self.error_page(utils.path + "var/export/epub/"+" already exists.\nYou should delete this folder.") + for article in articles_list: + if article_id == article[0]: + section = ez_epub.Section() + section.title = article[2] + section.paragraphs = [utils.clear_string(article[4])] + ez_epub.makeBook(article[2], [self.feeds[feed_id][3]], [section], \ + os.path.normpath(folder + "article"), lang='en-US', cover=None) + break + + epub.exposed = True + + + + def update(self, path=None, event = None): """ Synchronizes transient objects (dictionary of feed and articles) @@ -1207,6 +1251,11 @@ class Root: else: print "Base (%s) empty!" % utils.sqlite_base + + # + # Monitoring functions + # + def watch_base(self): """Monitor a file. @@ -1274,4 +1323,4 @@ if __name__ == '__main__': thread_watch_base = threading.Thread(None, root.watch_base_classic, None, ()) thread_watch_base.setDaemon(True) thread_watch_base.start() - cherrypy.quickstart(root, config=path) + cherrypy.quickstart(root, config=path)
\ No newline at end of file |