parent
c2b076f9ce
commit
b4501d60bc
|
@ -1,8 +1,8 @@
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<title>{{book["title"]}}</title>
|
<title>{{book["title"]}}</title>
|
||||||
{% if book["image"] is not equalto "" %}
|
{% if book["cover"] is not equalto "" %}
|
||||||
<p> cover: <img src="{{ url_for('static', filename="library_files/" + book["image"]) }}"> </p>
|
<p> <img src="{{ url_for('static', filename="library_files/" + book["cover"]) }}"> </p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for datum in (book|dictsort) %}
|
{% for datum in (book|dictsort) %}
|
||||||
<p> {{datum[0]}}: {{ datum[1] }} </p>
|
<p> {{names[datum[0]]}}: {{ datum[1] }} </p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
{% for book in books %}
|
{% for book in books %}
|
||||||
<tr>
|
<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 %}
|
{% for datum in attributes %}
|
||||||
<td> <a href="/book/{{book["id"]}}"> {{ book[datum] }} </a> </td>
|
<td> <a href="/book/{{book["id"]}}"> {{ book[datum] }} </a> </td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
15
test.py
15
test.py
|
@ -7,9 +7,11 @@ app = Flask(__name__)
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
attributes= ["title",
|
attributes= ["title",
|
||||||
"authors",
|
"author",
|
||||||
"isbn"]
|
"isbn"]
|
||||||
|
|
||||||
|
names = {}
|
||||||
|
|
||||||
def updateData():
|
def updateData():
|
||||||
out = []
|
out = []
|
||||||
|
|
||||||
|
@ -18,9 +20,14 @@ def updateData():
|
||||||
collection = tree.getroot()[0]
|
collection = tree.getroot()[0]
|
||||||
ns = "{http://periapsis.org/tellico/}"
|
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"):
|
for book in collection.iter(ns + "entry"):
|
||||||
bookout = {}
|
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["id"] = int(book.find(ns + "id").text)
|
||||||
bookout["title"] = book.find(ns + "title").text if (book.find(ns + "title") != None) else ""
|
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 ""
|
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:
|
if book.find(ns + "authors") != None:
|
||||||
for a in book.find(ns + "authors"):
|
for a in book.find(ns + "authors"):
|
||||||
authors.append(a.text)
|
authors.append(a.text)
|
||||||
bookout["authors"] = "; ".join(authors)
|
bookout["author"] = "; ".join(authors)
|
||||||
|
|
||||||
out.append(bookout.copy())
|
out.append(bookout.copy())
|
||||||
return out.copy()
|
return out.copy()
|
||||||
|
@ -42,7 +49,7 @@ def main():
|
||||||
def book(id):
|
def book(id):
|
||||||
data = updateData();
|
data = updateData();
|
||||||
book = next((item for item in data if item["id"] == id), {})
|
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__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True, host='0.0.0.0')
|
app.run(debug=True, host='0.0.0.0')
|
||||||
|
|
Loading…
Reference in New Issue