From b28e7a6d106f99abaaaa161951bb749d208453b3 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Wed, 17 Nov 2010 23:45:58 +0100 Subject: Introduction RSS export function. --- pyAggr3g470r.py | 115 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 43 deletions(-) (limited to 'pyAggr3g470r.py') diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 15353150..397fded4 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -187,7 +187,7 @@ class Root: html += article[1].encode('utf-8') + " - " + \ """%s%s%s%s""" % \ (rss_feed_id, article[0].encode('utf-8'), not_read_begin, \ - " ".join(article[2].encode('utf-8')[:150].split(' ')[:-1]), \ + " ".join(article[2].encode('utf-8')[:400].split(' ')[:-1]), \ not_read_end, description) + like + \ "
\n" html += "
\n" @@ -284,6 +284,7 @@ class Root: html += "

Export articles

\n\n" html += """
\n\t\n
\n""" @@ -1053,52 +1054,80 @@ class Root: Export articles stored in the SQLite database in text (raw or HTML) files. """ + if export_method == "export_RSS": + content = """ + + + + pyAggr3g470r RSS feed + http:// + + Cedric Bonhomme feeds + %s + %s + feeds.cgi + + """ % (time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()), \ + time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) + for rss_feed_id in self.feeds.keys(): - folder = utils.path + "/var/export/" + \ + if export_method != "export_RSS": + folder = utils.path + "/var/export/" + \ utils.normalize_filename(self.feeds[rss_feed_id][3].strip().encode("utf-8").replace(':', '').lower()) - try: - os.makedirs(folder) - except OSError: - return self.error_page(utils.path + "var/export/"+" already exists.\nYou should delete this folder.") + try: + os.makedirs(folder) + except OSError: + return self.error_page(utils.path + "var/export/"+" already exists.\nYou should delete this folder.") for article in self.articles[rss_feed_id]: - try: - name = article[1].strip().replace(' ', '_') - - # Export all articles in HTML format - if export_method == "export_HTML": - name = os.path.normpath(folder + "/" + name + ".html") - f = open(name, "w") - content = htmlheader() - content += '\n
\n' - content += """

%s


""" % \ - (article[3].encode('utf-8'), article[2].encode('utf-8')) - content += article[4].encode('utf-8') - content += "
\n
\n" - content += htmlfooter - # Export for dokuwiki - # example: http://wiki.cedricbonhomme.org/doku.php/news-archives - if export_method == "export_dokuwiki": - name = os.path.normpath(folder + "/" + name.replace(':', '-') + ".txt") - f = open(name, "w") - content = "" - content += '\n
\n' - content += """

%s


""" % \ - (article[3].encode('utf-8'), article[2].encode('utf-8')) - content += article[4].encode('utf-8') - content += '
\n
Generated with pyAggr3g470r\n' - # Export all articles in raw text - elif export_method == "export_TXT": - name = os.path.normpath(folder + "/" + name + ".txt") - f = open(name, "w") - content = "Title: " + article[2].encode('utf-8') + "\n\n\n" - content += utils.clear_string(article[4].encode('utf-8')) - - f.write(content) - except IOError: - pass - finally: - f.close() + name = article[1].strip().replace(' ', '_') + + # Export all articles in HTML format + if export_method == "export_HTML": + name = os.path.normpath(folder + "/" + name + ".html") + content = htmlheader() + content += '\n
\n' + content += """

%s


""" % \ + (article[3].encode('utf-8'), article[2].encode('utf-8')) + content += article[4].encode('utf-8') + content += "
\n
\n" + content += htmlfooter + # Export for dokuwiki + # example: http://wiki.cedricbonhomme.org/doku.php/news-archives + elif export_method == "export_dokuwiki": + name = os.path.normpath(folder + "/" + name.replace(':', '-') + ".txt") + content = "" + content += '\n
\n' + content += """

%s


""" % \ + (article[3].encode('utf-8'), article[2].encode('utf-8')) + content += article[4].encode('utf-8') + content += '
\n
Generated with pyAggr3g470r\n' + # Export all articles in RSS format + elif export_method == "export_RSS": + content += """\n%s\n%s\n""" % (article[2], article[3]) + content += """%s\n""" % (str(article[1]),) + content += """""" % (article[4],) + content += "\n" + # Export all articles in raw text + elif export_method == "export_TXT": + content = "Title: " + article[2].encode('utf-8') + "\n\n\n" + content += utils.clear_string(article[4].encode('utf-8')) + name = os.path.normpath(folder + "/" + name + ".txt") + if export_method != "export_RSS": + with open(name, "w") as f: + f.write(content) + + if export_method == "export_RSS": + content += "
\n
" + with open(os.path.normpath(utils.path + "/var/export/feeds.rss"), "w") as f: + f.write(content) return self.management() export.exposed = True -- cgit