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:
giomba 2018-10-21 14:10:16 +02:00
parent 6ed59e39fe
commit a72e51c7da
2 changed files with 19 additions and 2 deletions

17
main.py
View File

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

4
settings.py Normal file
View File

@ -0,0 +1,4 @@
# TPDF - Tellico Parser anD Finder -- MAIN CONFIGURATION FILE
# Path to Tellico .tc database to use
path = 'input/tellico.tc'