Commit 195d05ef authored by Mattia Bondanza's avatar Mattia Bondanza

Correct a bug for the generation of db path and changed the return logic of searchISBN function.

parent 9468a20c
......@@ -57,19 +57,7 @@ def metadataFromISBN( isbn ):
if len( mtd['author'] ) > 0:
mtd['author']=mtd['author'][0:len(mtd['author'])-2]
return mtd
'''
def metadataISBNGetAuthor( mdt ):
if 'author' in mdt['list'][0]:
return mdt['list'][0]['author']
else:
return None
def metadataISBNGetTitle( mdt ):
if 'title' in mdt['list'][0]:
return mdt['list'][0]['title']
else:
return None
'''
def printMetadataForISBN( isbn ):
mdt = metadataFromISBN( isbn )
if mdt['author'] is not '' and mdt['title'] is not '':
......
......@@ -50,7 +50,8 @@ else :
settings.verbosity_level_numeric = 1
print "verbosity level: ", settings.verbosity_level_numeric
db_file_path = args.directory[0]+".bao_sqlite.db"
db_file_path = os.path.join(args.directory[0], ".bao_sqlite.db" )
if settings.verbosity_level_numeric > 0:
print "[database]\tInitializing database " + db_file_path + " ..."
db_init( db_file_path, args.tmp_directory[0] )
......@@ -169,11 +170,11 @@ for path, subdirs, files in os.walk( args.directory[0] ):
if len( cnt ) == 0:
if settings.verbosity_level_numeric > 0:
print "[ISBNsrch]\tFailed extracting text with Tesseract"
ISBNstrings = None
ISBNstrings = []
else:
ISBNstrings = searchISBNstrings( cnt )
if ISBNstrings is None:
if len( ISBNstrings ) == 0:
if settings.verbosity_level_numeric > 0:
print "[ISBNsrch]\t\x1b[31m No ISBN string found. \x1b[0m"
else:
......
......@@ -51,7 +51,7 @@ def getTextWithOCR( path, temporary_file_directory = '/tmp' ):
def searchISBNstrings( cnt ):
bg = 0
out = []
#Da migliorare!
pos = cnt.find("ISBN")
while pos != -1 :
old_len=len(out)
......@@ -90,6 +90,7 @@ def searchISBNstrings( cnt ):
OpenLibrary.printMetadataForISBN( out[len(out)-1] )
if settings.verbosity_level_numeric > 1:
print
elif strippedisbn[0:2] == '13':#Puo' essere un ISBN10 che comincia con 13 oppure un ISBN13 con 13 davanti. Non può essere ISBN13 che inizia con 13 perché le prime 3 cifre sono sempre 978 per ISBN13
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\tPenso sia un ISBN13."
......@@ -128,16 +129,13 @@ def searchISBNstrings( cnt ):
OpenLibrary.printMetadataForISBN( out[len(out)-1] )
if settings.verbosity_level_numeric > 1:
print
if len(out) == old_len:
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\t\x1b[1m\x1b[34mNon ho aggiunto nulla.\x1b[22m\x1b[0m "
bg = pos
pos = cnt.find("ISBN", bg+1 )
if len( out ) == 0:
return None
else:
return out
return out
def checkISBN10( isbn ):
if len( isbn ) != 10 :
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment