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 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)
|
||||
|
|
|
@ -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