From f7660befccccb25475e19963926b6200fcbb500b Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 8 Dec 2013 14:16:25 +0100 Subject: The name of the archive is composed of the current date. --- pyaggr3g470r/export.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'pyaggr3g470r/export.py') diff --git a/pyaggr3g470r/export.py b/pyaggr3g470r/export.py index 987be217..9d03f42b 100644 --- a/pyaggr3g470r/export.py +++ b/pyaggr3g470r/export.py @@ -34,8 +34,10 @@ __license__ = "GPLv3" # import os +import shutil import time import tarfile +from datetime import datetime import conf import utils @@ -134,13 +136,14 @@ def export_html(feeds): """ Export the articles given in parameter in a simple Webzine. """ + webzine_root = conf.PATH + "/pyaggr3g470r/var/export/webzine/" nb_articles = format(len(models.Article.objects()), ",d") index = HTML_HEADER("News archive") index += "

List of feeds

\n" index += """

%s articles.

\n\n" index += "

" + time.strftime("Generated on %d %b %Y at %H:%M.") + "

\n" index += HTML_FOOTER - with open(conf.PATH + "/pyaggr3g470r/var/export/webzine/" + "index.html", "w") as f: + with open(webzine_root + "index.html", "w") as f: f.write(index.encode("utf-8")) - with open(conf.PATH + "/pyaggr3g470r/var/export/webzine/" + "style.css", "w") as f: + with open(webzine_root + "style.css", "w") as f: f.write(CSS.encode("utf-8")) - with tarfile.open(conf.PATH + "/pyaggr3g470r/var/export.tar.gz", "w:gz") as tar: - tar.add(conf.PATH + "/pyaggr3g470r/var/export/webzine/", arcname=os.path.basename(conf.PATH + "/pyaggr3g470r/var/export/webzine/")) + archive_file_name = datetime.now().strftime('%Y-%m-%d') + '.tar.gz' + with tarfile.open(conf.PATH + "/pyaggr3g470r/var/export/" + archive_file_name, "w:gz") as tar: + tar.add(webzine_root, arcname=os.path.basename(webzine_root)) + + shutil.rmtree(webzine_root) + + with open(conf.PATH + "/pyaggr3g470r/var/export/" + archive_file_name, 'r') as export_file: + return export_file.read(), archive_file_name def export_txt(mongo_db): """ -- cgit