diff --git a/main.py b/main.py index f81f88f..cf9632a 100755 --- a/main.py +++ b/main.py @@ -21,9 +21,13 @@ import xml.etree.ElementTree as ET import json import sys import cgitb, cgi +import zipfile +import tempfile +import shutil as sh # Our custom library (again no pun intended) import tcparser +import settings # Start CGI handling for webserver cgitb.enable() @@ -45,8 +49,14 @@ print() ### End of HTTP headers: it is now safe to output things ########################################################## -# Get a Python-friendly library struct -library = tcparser.getLibrary('input/tellico.xml') +# Unzip Tellico .tc database in temporary directory +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 ### try: @@ -68,3 +78,6 @@ if format == 'html': if format == 'json': # Wanna get a pretty JSON encoded library to do your nasty things offline at home? ;-) print(json.dumps(result, indent=4)) + +# Delete temp files +sh.rmtree(tmpOutDir) diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..b07299d --- /dev/null +++ b/settings.py @@ -0,0 +1,4 @@ +# TPDF - Tellico Parser anD Finder -- MAIN CONFIGURATION FILE + +# Path to Tellico .tc database to use +path = 'input/tellico.tc'