Removed bulky backend
This commit is contained in:
parent
246529942f
commit
4919486f10
|
@ -69,7 +69,7 @@ class TPDF {
|
|||
|
||||
|
||||
titleElement.appendChild(document.createTextNode(results['books'][i]['title']));
|
||||
coverElement.src = 'https://golem.linux.it/cgi/tpdf/output/images/' + results['books'][i]['cover'];
|
||||
coverElement.src = 'output/images/' + results['books'][i]['cover'];
|
||||
coverElement.alt = 'Cover of «' + results['books'][i]['title'] + '»';
|
||||
|
||||
bookElement.appendChild(titleElement);
|
||||
|
@ -90,7 +90,7 @@ class TPDF {
|
|||
TPDF.xhr = new XMLHttpRequest();
|
||||
TPDF.xhr.onload = TPDF.display;
|
||||
TPDF.xhr.open('GET',
|
||||
'https://golem.linux.it/cgi/tpdf/main.py?format=json' +
|
||||
'main.py?format=json' +
|
||||
'&author=' + encodeURIComponent(document.querySelector('#tpdfForm input[name="author"]').value) +
|
||||
'&title=' + encodeURIComponent(document.querySelector('#tpdfForm input[name="title"]').value));
|
||||
TPDF.xhr.send(null);
|
||||
|
|
24
main.py
24
main.py
|
@ -35,20 +35,9 @@ import glob
|
|||
cgitb.enable()
|
||||
inputvars = cgi.FieldStorage()
|
||||
|
||||
# Detect desired format
|
||||
try:
|
||||
format = inputvars['format'].value
|
||||
except KeyError:
|
||||
format = 'html'
|
||||
|
||||
if format == 'html':
|
||||
print('Content-Type: text/html; charset=utf-8')
|
||||
else:
|
||||
print('Content-Type: text/json; charset=utf-8')
|
||||
print('Access-Control-Allow-Origin: *')
|
||||
|
||||
print('Content-Type: text/json; charset=utf-8')
|
||||
print('Access-Control-Allow-Origin: *')
|
||||
print()
|
||||
|
||||
### End of HTTP headers: it is now safe to output things
|
||||
##########################################################
|
||||
|
||||
|
@ -93,10 +82,5 @@ except KeyError:
|
|||
|
||||
result = tcparser.filter(library, title=title, author=author)
|
||||
|
||||
if format == 'html':
|
||||
htmlTree = tcparser.getHTML(result)
|
||||
htmlString = ET.tostring(htmlTree.getroot(), encoding='unicode', method='html')
|
||||
print(htmlString)
|
||||
if format == 'json':
|
||||
# Wanna get a pretty JSON encoded library to do your nasty things offline at home? ;-)
|
||||
print(json.dumps(result, indent=4))
|
||||
# Wanna get a pretty JSON encoded library to do your nasty things offline at home? ;-)
|
||||
print(json.dumps(result, indent=4))
|
||||
|
|
17
style.css
17
style.css
|
@ -22,23 +22,6 @@ body {
|
|||
margin: 3px;
|
||||
}
|
||||
|
||||
/* table {
|
||||
margin: 0 auto;
|
||||
border: 1px solid black;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
thead {
|
||||
background-color: #CECECE;
|
||||
position: sticky;
|
||||
top: 0px;
|
||||
}
|
||||
|
||||
td, th {
|
||||
padding: 2px;
|
||||
border: 1px solid black;
|
||||
} */
|
||||
|
||||
#tpdfOutput img {
|
||||
margin: 2px;
|
||||
display: inline-block;
|
||||
|
|
105
tcparser.py
105
tcparser.py
|
@ -48,111 +48,6 @@ def getLibrary(path, lastUpdate):
|
|||
|
||||
return library
|
||||
|
||||
# Given a custom Python-friendly library struct, get the HTML version of it
|
||||
# Very useful for our webserver
|
||||
def getHTML(library):
|
||||
# Build the XML/HTML tree
|
||||
tree = ET.ElementTree()
|
||||
|
||||
# Headers and other stuff needed for properly formatted HTML documents
|
||||
# plus some titles
|
||||
html = ET.Element('html')
|
||||
head = ET.Element('head')
|
||||
title = ET.Element('title')
|
||||
linkstyle = ET.Element('link', attrib={'rel': 'stylesheet', 'type': 'text/css', 'media':'all', 'href': 'style.css'})
|
||||
metacharset = ET.Element('meta', attrib={'charset': 'utf-8'})
|
||||
body = ET.Element('body')
|
||||
main = ET.Element('main')
|
||||
table = ET.Element('table')
|
||||
h1 = ET.Element('h1')
|
||||
|
||||
title.text = h1.text = 'TPDF - Tellico Parser anD Finder ' + glob.version
|
||||
|
||||
tree._setroot(html)
|
||||
html.append(head)
|
||||
head.append(title)
|
||||
head.append(metacharset)
|
||||
head.append(linkstyle)
|
||||
html.append(body)
|
||||
body.append(main)
|
||||
main.append(h1)
|
||||
|
||||
# Last database update string
|
||||
p = ET.Element('p')
|
||||
# p.text = 'Last DB update: ' + str(main.lu)
|
||||
p.text = 'Last database update ' + datetime.date.fromtimestamp(library['lastupdate']).strftime('%d %B %Y')
|
||||
main.append(p)
|
||||
|
||||
# Check for empty resultset
|
||||
if len(library['books']) == 0:
|
||||
p = ET.Element('p')
|
||||
p.text = "No items"
|
||||
main.append(p)
|
||||
return tree
|
||||
|
||||
main.append(table)
|
||||
|
||||
# Build a beautiful table header
|
||||
thead = ET.Element('thead')
|
||||
tr = ET.Element('tr')
|
||||
|
||||
table.append(thead)
|
||||
thead.append(tr)
|
||||
|
||||
for i in ('ID', 'Cover', 'Title', 'Publisher', 'Year', 'ISBN', 'Pages', 'Author'):
|
||||
th = ET.Element('th')
|
||||
th.text = i
|
||||
tr.append(th)
|
||||
|
||||
# Add a row in our table for every book in the library object
|
||||
for i in library['books']:
|
||||
tr = ET.Element('tr')
|
||||
|
||||
id = ET.Element('td')
|
||||
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': glob.conf['default']['outdir'] + '/images/' + i.get('cover')})
|
||||
cover.append(img)
|
||||
|
||||
tr.append(cover)
|
||||
|
||||
title = ET.Element('td')
|
||||
title.text = i.get('title')
|
||||
tr.append(title)
|
||||
|
||||
publisher = ET.Element('td');
|
||||
publisher.text = i.get('publisher')
|
||||
tr.append(publisher)
|
||||
|
||||
year = ET.Element('td')
|
||||
year.text = str(i.get('year', ''))
|
||||
tr.append(year)
|
||||
|
||||
isbn = ET.Element('td')
|
||||
isbn.text = i.get('isbn')
|
||||
tr.append(isbn)
|
||||
|
||||
pages = ET.Element('td')
|
||||
pages.text = str(i.get('pages', ''))
|
||||
tr.append(pages)
|
||||
|
||||
authors = ET.Element('td')
|
||||
ul = ET.Element('ul')
|
||||
authors.append(ul)
|
||||
for j in i['authors']:
|
||||
li = ET.Element('li')
|
||||
li.text = j
|
||||
ul.append(li)
|
||||
tr.append(authors)
|
||||
|
||||
table.append(tr)
|
||||
|
||||
# Our nice XML/HTML tree
|
||||
return tree
|
||||
|
||||
# Filter results using following filter functions and order by title
|
||||
####################################################################
|
||||
def filter(library, title='', author=''):
|
||||
|
|
Loading…
Reference in New Issue