tellicoViewer/test.py
Adam Goldsmith 2228672a16 switch to individual parsing of data
allows for exceptions like authors, date, etc.
will hopefully switch back as soon as I figure out a generic way to do so
2015-08-08 19:24:14 -04:00

35 lines
1.0 KiB
Python

#!/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 = {}
bookout["title"] = book.find(ns + "title").text if (book.find(ns + "title") != None) else ""
bookout["isbn"] = book.find(ns + "isbn").text if (book.find(ns + "isbn") != None) else ""
authors = []
if book.find(ns + "authors") != None:
for a in book.find(ns + "authors"):
authors.append(a.text)
bookout["authors"] = "; ".join(authors)
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')