From f8b61ef5e163607731b992f9fdf0ec5840e5daaf Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Thu, 6 Oct 2016 10:40:55 +0200 Subject: The export to HTML webzine functionality has been removed. --- src/web/export.py | 198 +++----------------------------------- src/web/templates/management.html | 4 - src/web/views/article.py | 21 +--- 3 files changed, 18 insertions(+), 205 deletions(-) (limited to 'src/web') diff --git a/src/web/export.py b/src/web/export.py index 9d9448df..048dc064 100644 --- a/src/web/export.py +++ b/src/web/export.py @@ -20,190 +20,21 @@ # along with this program. If not, see . __author__ = "Cedric Bonhomme" -__version__ = "$Revision: 0.6 $" +__version__ = "$Revision: 0.7 $" __date__ = "$Date: 2011/10/24 $" -__revision__ = "$Date: 2014/04/12 $" +__revision__ = "$Date: 2016/10/06 $" __copyright__ = "Copyright (c) Cedric Bonhomme" __license__ = "AGPLv3" # -# This file contains the export functions of jarr. Indeed -# it is possible to export the database of articles in different formats: -# - simple HTML webzine; -# - text file. +# This file contains the export functions of jarr. # -import os -import shutil -import time -import tarfile -from datetime import datetime - from flask import jsonify -import conf -from web import models - - -def HTML_HEADER(title="jarr", css="./style.css"): - return """ - - -%s - - - -""" % (title, css) - -HTML_FOOTER = """
-

This archive has been generated with -jarr. -A software under AGPLv3 license. -You are welcome to copy, modify or redistribute the source code according to the -AGPLv3 license.

- - -""" - -CSS = """body { - font:normal medium 'Gill Sans','Gill Sans MT',Verdana,sans-serif; - margin:1.20em auto; - width:80%; - line-height:1.75; -} -blockquote { - font-size:small; - line-height:2.153846; - margin:2.153846em 0; - padding:0;font-style:oblique; - border-left:1px dotted; - margin-left:2.153846em; - padding-left:2.153846em; -} -blockquote p{ - margin:2.153846em 0; -} -p+br { - display:none; -} -h1 { -font-size:large; -} -h2,h3 { - font-size:medium; -} -hr { - border-style:dotted; - height:1px; - border-width: 1px 0 0 0; - margin:1.45em 0 1.4em; - padding:0; -} -a { - text-decoration:none; - color:#00008B; -} -#footer { - clear:both; - text-align:center; - font-size:small; -} -img { - border:0; -} -.horizontal,.simple li { - margin:0; - padding:0; - list-style:none; - display:inline -} -.simple li:before { - content:"+ "; -} -.simple > li:first-child:before { - content:""; -} -.author { - text-decoration:none; - display:block; - float:right; - margin-left:2em; - font-size:small; -} -.content { - margin:1.00em 1.00em; -}""" - - -def export_html(user): - """ - Export all articles of 'user' in Web pages. - """ - webzine_root = conf.WEBZINE_ROOT + "/webzine/" - nb_articles = format(len(models.Article.query.filter(models.Article.user_id == user.id).all()), ",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(webzine_root + "index.html", "w") as f: - f.write(index) - with open(webzine_root + "style.css", "w") as f: - f.write(CSS) - - archive_file_name = datetime.now().strftime('%Y-%m-%d') + '.tar.gz' - with tarfile.open(conf.WEBZINE_ROOT + archive_file_name, "w:gz") as tar: - tar.add(webzine_root, arcname=os.path.basename(webzine_root)) - - shutil.rmtree(webzine_root) - - with open(conf.WEBZINE_ROOT + archive_file_name, 'rb') as export_file: - return export_file.read(), archive_file_name - def export_json(user): """ - Export all articles of 'user' in JSON. + Export all articles of user in JSON. """ result = [] for feed in user.feeds: @@ -215,16 +46,13 @@ def export_json(user): "enabled": feed.enabled, "created_date": feed.created_date.strftime('%s'), "articles": [ { - "title": article.title, - "link": article.link, - "content": article.content, - "readed": article.readed, - "like": article.like, - "date": article.date.strftime('%s'), - "retrieved_date": article.retrieved_date.strftime('%s') - } - for article in feed.articles - ] - }) - + "title": article.title, + "link": article.link, + "content": article.content, + "readed": article.readed, + "like": article.like, + "date": article.date.strftime('%s'), + "retrieved_date": article.retrieved_date.strftime('%s') + } for article in feed.articles ] + }) return jsonify(result=result) diff --git a/src/web/templates/management.html b/src/web/templates/management.html index eaf1de31..2f5eda6f 100644 --- a/src/web/templates/management.html +++ b/src/web/templates/management.html @@ -24,9 +24,5 @@
{{ _('Export account to JSON') }} -
-

{{ _('Export articles') }}

- HTML -
{% endblock %} diff --git a/src/web/views/article.py b/src/web/views/article.py index eed9a9d3..572c019e 100644 --- a/src/web/views/article.py +++ b/src/web/views/article.py @@ -7,7 +7,7 @@ from flask_login import login_required, current_user from bootstrap import db -from web.export import export_json, export_html +from web.export import export_json from web.lib.utils import clear_string, redirect_url from web.controllers import (ArticleController, UserController, CategoryController) @@ -125,23 +125,11 @@ def expire(): @login_required def export(): """ - Export all articles to HTML or JSON. + Export to OPML or JSON. """ user = UserController(current_user.id).get(id=current_user.id) - if request.args.get('format') == "HTML": - # Export to HTML - try: - archive_file, archive_file_name = export_html(user) - except Exception as e: - print(e) - flash(gettext("Error when exporting articles."), 'danger') - return redirect(redirect_url()) - response = make_response(archive_file) - response.headers['Content-Type'] = 'application/x-compressed' - response.headers['Content-Disposition'] = 'attachment; filename=%s' \ - % archive_file_name - elif request.args.get('format') == "JSON": - # Export to JSON + if request.args.get('format') == "JSON": + # Export to JSON for the export of account. try: json_result = export_json(user) except Exception as e: @@ -152,6 +140,7 @@ def export(): response.headers["Content-Disposition"] \ = 'attachment; filename=account.json' elif request.args.get('format') == "OPML": + # Export to the OPML format. categories = {cat.id: cat.dump() for cat in CategoryController(user.id).read()} response = make_response(render_template('opml.xml', user=user, -- cgit