diff options
author | Jordan <me@jordan.im> | 2020-04-05 23:55:56 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2020-04-05 23:55:56 -0700 |
commit | 759800be93dfffd9ae48457817705a11b73c31f7 (patch) | |
tree | 3ca03ffdef87fe34c2d05141553ef06ae657b07e | |
parent | 5d2827f8ba1f2ebeaef347fd7dd62f2de845cf99 (diff) | |
download | roka-759800be93dfffd9ae48457817705a11b73c31f7.tar.gz roka-759800be93dfffd9ae48457817705a11b73c31f7.zip |
prettify XML response
-rwxr-xr-x | run.py | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -9,6 +9,7 @@ from collections import OrderedDict from operator import getitem from datetime import date, timedelta from flask import Flask, request, Response, render_template, send_file +from xml.dom import minidom abs_path = os.path.dirname(os.path.abspath(__file__)) app = Flask(__name__) @@ -40,6 +41,15 @@ def check_auth(username, password): return ret +def xml_prettify(elem): + ''' + Make our XML response human-readable + ''' + xml_str = ET.tostring(elem, encoding='utf8', method='xml') + xml_dom = minidom.parseString(xml_str) + + return xml_dom.toprettyxml(indent=' ') + @app.route('/') def list_books(): ''' @@ -181,10 +191,7 @@ def list_books(): } ET.SubElement(item, 'enclosure', enc_attr) - return Response( - ET.tostring(rss, encoding='utf8', method='xml'), - mimetype='text/xml' - ) + return Response(xml_prettify(rss), mimetype='text/xml') else: auth = request.authorization if not auth or not check_auth(auth.username, auth.password): |