aboutsummaryrefslogtreecommitdiff
path: root/pyAggr3g470r.py
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-05-03 21:59:30 +0200
committercedricbonhomme <devnull@localhost>2010-05-03 21:59:30 +0200
commit9e4a8f0b593970e5a35c28a102b5d80e423cb349 (patch)
treee8a2e974fc55fb7448a7533b4d5165f54b29e55f /pyAggr3g470r.py
parentRelease 1.2. Added tag cloud, minor bug fix, CSS improvements. (diff)
downloadnewspipe-9e4a8f0b593970e5a35c28a102b5d80e423cb349.tar.gz
newspipe-9e4a8f0b593970e5a35c28a102b5d80e423cb349.tar.bz2
newspipe-9e4a8f0b593970e5a35c28a102b5d80e423cb349.zip
Added export function.
Diffstat (limited to 'pyAggr3g470r.py')
-rwxr-xr-xpyAggr3g470r.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py
index 30ba48e4..fec8db74 100755
--- a/pyAggr3g470r.py
+++ b/pyAggr3g470r.py
@@ -207,8 +207,13 @@ class Root:
html += """<form method=get action="/fetch/">\n<input
type="submit" value="Fetch all feeds"></form>\n"""
- html += """<form method=get action="add_feed/">\n<input
+ html += """<form method=get action="/add_feed/">\n<input
type="submit" value="Delete all articles"></form>\n"""
+ html += "<h1>Export articles</h1>"
+ html += """<form method=get action="/export/"><select name="export_method">\n"""
+ html += """\t<option value="export_HTML" selected='selected'>HTML</option>\n"""
+ html += """\t<option value="export_TXT">Text</option>\n"""
+ html += """</select><input type="submit" value="Export"></form>\n"""
html += "<hr />\n"
if self.articles:
@@ -742,6 +747,34 @@ class Root:
list_favorites.exposed = True
+ def export(self, export_method):
+ """
+ Export articles stored in the SQLite database in a text files.
+ """
+ for rss_feed_id in self.feeds.keys():
+ folder = "./var/export/" + self.feeds[rss_feed_id][3]
+ try:
+ os.makedirs(folder)
+ except OSError:
+ return self.error_page(folder+" already exists.")
+ for article in self.articles[rss_feed_id]:
+ try:
+ if export_method == "export_HTML":
+ f = open(folder + "/" + article[2]+ ".html", "w")
+ content = article[4].encode('utf-8')
+ elif export_method == "export_TXT":
+ f = open(folder + "/" + article[2], "w")
+ content = utils.remove_html_tags(article[4].encode('utf-8'))
+ f.write(content)
+ except IOError:
+ pass
+ finally:
+ f.close()
+ return self.management()
+
+ export.exposed = True
+
+
def update(self, path=None, event = None):
"""
Synchronizes transient objects with the database,
bgstack15