From 1a085b68c51b65d567f7db381379893f3bc3cde0 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 7 Aug 2015 11:55:21 -0400 Subject: [PATCH] initial commit --- templates/books.html | 16 ++++++++++++++++ test.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 templates/books.html create mode 100644 test.py diff --git a/templates/books.html b/templates/books.html new file mode 100644 index 0000000..b179bbf --- /dev/null +++ b/templates/books.html @@ -0,0 +1,16 @@ + +Test App + + + {% for datum in data %} + + {% endfor %} + + {% for book in books %} + + {% for datum in data %} + + {% endfor %} + + {% endfor %} +
{{ datum }}
{{ book[datum] }}
diff --git a/test.py b/test.py new file mode 100644 index 0000000..11c938d --- /dev/null +++ b/test.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +from xml.etree import ElementTree +import zipfile +from flask import Flask, render_template +app = Flask(__name__) + +@app.route("/") +def main(): + out = [] + data = ["title", + "authors", + "isbn"] + + f = zipfile.ZipFile("library.tc") + tree = ElementTree.parse(f.open("tellico.xml")) + collection = tree.getroot()[0] + ns = "{http://periapsis.org/tellico/}" + + for book in collection.iter(ns + "entry"): + bookout = {} + for datum in data: + d = book.find(ns + datum) + bookout[datum] = d.text if (d != None) else "" + out.append(bookout.copy()) + return render_template("books.html", books = out, data = data) + +if __name__ == "__main__": + app.run(debug=True, host='0.0.0.0')