diff --git a/.gitignore b/.gitignore index 0c9e0fd..4fb8631 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ test/ input/ +images/ diff --git a/TODO b/TODO index e69de29..c8f733a 100644 --- a/TODO +++ b/TODO @@ -0,0 +1,2 @@ +- Improve file unzip and images storage with some caching method + Don't use the copy from the temporary directory diff --git a/main.py b/main.py index cf9632a..8e86fd7 100755 --- a/main.py +++ b/main.py @@ -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") diff --git a/style.css b/style.css index 63c7b29..5807e17 100644 --- a/style.css +++ b/style.css @@ -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; +} diff --git a/tcparser.py b/tcparser.py index c55af88..de04339 100644 --- a/tcparser.py +++ b/tcparser.py @@ -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)