Added images of covers

This commit is contained in:
giomba 2018-10-21 15:00:19 +02:00
parent a72e51c7da
commit b6e818d66d
5 changed files with 23 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
__pycache__/
test/
input/
images/

2
TODO
View File

@ -0,0 +1,2 @@
- Improve file unzip and images storage with some caching method
Don't use the copy from the temporary directory

View File

@ -54,6 +54,9 @@ tmpOutDir = tempfile.mkdtemp()
zipHandler = zipfile.ZipFile(settings.path, 'r')
zipHandler.extractall(tmpOutDir)
zipHandler.close()
# Move images to webserver folder
sh.rmtree('./images')
sh.move(tmpOutDir + '/images', '.')
# Get a Python-friendly library struct from XML file
library = tcparser.getLibrary(tmpOutDir + "/tellico.xml")

View File

@ -26,9 +26,16 @@ table {
thead {
background-color: #CECECE;
position: sticky;
top: 0px;
}
td, th {
padding: 2px;
border: 1px solid black;
}
img {
max-width: 200px;
max-height: 200px;
}

View File

@ -37,6 +37,8 @@ def getLibrary(path):
newbook['isbn'] = j.text.replace('-', '')
for j in i.iter('pages'):
newbook['pages'] = int(j.text)
for j in i.iter('cover'):
newbook['cover'] = j.text
newbook['authors'] = list()
for j in i.iter('authors'):
for k in j.findall('author'):
@ -91,7 +93,7 @@ def getHTML(library):
table.append(thead)
thead.append(tr)
for i in ('ID', 'Title', 'Publisher', 'Year', 'ISBN', 'Pages', 'Author'):
for i in ('ID', 'Cover', 'Title', 'Publisher', 'Year', 'ISBN', 'Pages', 'Author'):
th = ET.Element('th')
th.text = i
tr.append(th)
@ -104,6 +106,13 @@ def getHTML(library):
id.text = str(i.get('id'))
tr.append(id)
cover = ET.Element('td')
if i.get('cover'):
img = ET.Element('img', attrib={'alt': 'Book "' + i.get('title') + '" cover', 'src': 'images/' + i.get('cover')})
cover.append(img)
tr.append(cover)
title = ET.Element('td')
title.text = i.get('title')
tr.append(title)