lookup pretty names from file

standardize names to match
This commit is contained in:
Adam Goldsmith 2015-08-09 20:13:44 -04:00
parent c2b076f9ce
commit b4501d60bc
3 changed files with 15 additions and 8 deletions

View File

@ -1,8 +1,8 @@
<!doctype html>
<title>{{book["title"]}}</title>
{% if book["image"] is not equalto "" %}
<p> cover: <img src="{{ url_for('static', filename="library_files/" + book["image"]) }}"> </p>
{% if book["cover"] is not equalto "" %}
<p> <img src="{{ url_for('static', filename="library_files/" + book["cover"]) }}"> </p>
{% endif %}
{% for datum in (book|dictsort) %}
<p> {{datum[0]}}: {{ datum[1] }} </p>
<p> {{names[datum[0]]}}: {{ datum[1] }} </p>
{% endfor %}

View File

@ -9,7 +9,7 @@
</tr>
{% for book in books %}
<tr>
<td> <img height="100px" width="50px" src="{{ url_for('static', filename="library_files/" + book["image"]) }}"> </td>
<td> <img height="100px" width="50px" src="{{ url_for('static', filename="library_files/" + book["cover"]) }}"> </td>
{% for datum in attributes %}
<td> <a href="/book/{{book["id"]}}"> {{ book[datum] }} </a> </td>
{% endfor %}

15
test.py
View File

@ -7,9 +7,11 @@ app = Flask(__name__)
data = []
attributes= ["title",
"authors",
"author",
"isbn"]
names = {}
def updateData():
out = []
@ -18,9 +20,14 @@ def updateData():
collection = tree.getroot()[0]
ns = "{http://periapsis.org/tellico/}"
for field in collection.find(ns + "fields"):
print(field.attrib)
if "title" in field.attrib:
names[field.attrib["name"]] = field.attrib["title"]
for book in collection.iter(ns + "entry"):
bookout = {}
bookout["image"] = book.find(ns + "cover").text if book.find(ns + "cover") != None else ""
bookout["cover"] = book.find(ns + "cover").text if book.find(ns + "cover") != None else ""
bookout["id"] = int(book.find(ns + "id").text)
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 ""
@ -28,7 +35,7 @@ def updateData():
if book.find(ns + "authors") != None:
for a in book.find(ns + "authors"):
authors.append(a.text)
bookout["authors"] = "; ".join(authors)
bookout["author"] = "; ".join(authors)
out.append(bookout.copy())
return out.copy()
@ -42,7 +49,7 @@ def main():
def book(id):
data = updateData();
book = next((item for item in data if item["id"] == id), {})
return render_template("book.html", book = book)
return render_template("book.html", book = book, names = names)
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')