Read directly from .tc database
Now takes the .tc database archive and extracts needed files automatically, without requiring manual extraction of .xml
This commit is contained in:
parent
6ed59e39fe
commit
a72e51c7da
17
main.py
17
main.py
|
@ -21,9 +21,13 @@ import xml.etree.ElementTree as ET
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import cgitb, cgi
|
import cgitb, cgi
|
||||||
|
import zipfile
|
||||||
|
import tempfile
|
||||||
|
import shutil as sh
|
||||||
|
|
||||||
# Our custom library (again no pun intended)
|
# Our custom library (again no pun intended)
|
||||||
import tcparser
|
import tcparser
|
||||||
|
import settings
|
||||||
|
|
||||||
# Start CGI handling for webserver
|
# Start CGI handling for webserver
|
||||||
cgitb.enable()
|
cgitb.enable()
|
||||||
|
@ -45,8 +49,14 @@ print()
|
||||||
### End of HTTP headers: it is now safe to output things
|
### End of HTTP headers: it is now safe to output things
|
||||||
##########################################################
|
##########################################################
|
||||||
|
|
||||||
# Get a Python-friendly library struct
|
# Unzip Tellico .tc database in temporary directory
|
||||||
library = tcparser.getLibrary('input/tellico.xml')
|
tmpOutDir = tempfile.mkdtemp()
|
||||||
|
zipHandler = zipfile.ZipFile(settings.path, 'r')
|
||||||
|
zipHandler.extractall(tmpOutDir)
|
||||||
|
zipHandler.close()
|
||||||
|
|
||||||
|
# Get a Python-friendly library struct from XML file
|
||||||
|
library = tcparser.getLibrary(tmpOutDir + "/tellico.xml")
|
||||||
|
|
||||||
### Get filters to search for books ###
|
### Get filters to search for books ###
|
||||||
try:
|
try:
|
||||||
|
@ -68,3 +78,6 @@ if format == 'html':
|
||||||
if format == 'json':
|
if format == 'json':
|
||||||
# Wanna get a pretty JSON encoded library to do your nasty things offline at home? ;-)
|
# Wanna get a pretty JSON encoded library to do your nasty things offline at home? ;-)
|
||||||
print(json.dumps(result, indent=4))
|
print(json.dumps(result, indent=4))
|
||||||
|
|
||||||
|
# Delete temp files
|
||||||
|
sh.rmtree(tmpOutDir)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
# TPDF - Tellico Parser anD Finder -- MAIN CONFIGURATION FILE
|
||||||
|
|
||||||
|
# Path to Tellico .tc database to use
|
||||||
|
path = 'input/tellico.tc'
|
Loading…
Reference in New Issue