Commit 5bdb4061 authored by Mattia Bondanza's avatar Mattia Bondanza

Now the _isbn tables in the database are filled up with the metadatas

parent d40709c9
......@@ -39,18 +39,18 @@ def add_book( db_file, path ):
db.execute( "INSERT INTO library VALUES ( :md5, :path )", { 'md5':md5, 'path': path } )
db_con.commit()
db.execute( "CREATE TABLE {} ( author, title, year, edition, ISBN, found_ISBN )".format( '_'+md5 ) )
db.execute( "CREATE TABLE {}_isbn ( ISBN_string, ISBN, author, title, source )".format( '_'+md5 ) )
db.execute( "CREATE TABLE {}_isbn ( ISBN, author, title, source )".format( '_'+md5 ) )
if settings.verbosity_level_numeric > 0:
print( "[database]\tFile {} inserted in the database.".format( path ))
db_con.close()
return True
def add_isbn( db_file, path, ISBN_string, ISBN, author, title, source ):
def add_isbn( db_file, path, ISBN, author, title, source ):
db_con = sqlite3.connect( db_file )
db = db_con.cursor()
md5 = md5sum( path )
db.execute( "INSERT INTO {}_isbn VALUES ( :isbnstring, :isbn, :auth, :title, :source )".format( '_'+md5 ),
{ 'isbnstring': ISBN_string, 'isbn': ISBN, 'auth': author, 'title': title, 'source': source } )
db.execute( "INSERT INTO {}_isbn VALUES ( :isbn, :auth, :title, :source )".format( '_'+md5 ),
{ 'isbn': ISBN, 'auth': author, 'title': title, 'source': source } )
db_con.commit()
db_con.close()
......@@ -9,6 +9,8 @@ import argparse
import settings
from bao_database import add_book, add_isbn, db_init
import OpenLibrary
import isbnPLUS
#-----Argument parsing-------#
......@@ -196,9 +198,15 @@ for path, subdirs, files in os.walk( args.directory[0] ):
if settings.verbosity_level_numeric > 0:
print "[ISBNsrch]\t\x1b[34m Found", len(ISBNstrings),"ISBN strings.\x1b[0m"
#Replace with database calls
for isbn in ISBNstrings:
add_isbn( db_file_path, os.path.join( path, name ), isbn, 'foo', 'foo', 'foo', 'foo' )
OLmdt = OpenLibrary.metadataFromISBN( isbn )
if OLmdt['author'] is not '' and OLmdt['title'] is not '':
add_isbn( db_file_path, os.path.join( path, name ), isbn, OLmdt['author'], OLmdt['title'], 'OpenLibrary' )
ISBNPLUSmdt = isbnPLUS.metadataFromISBN( isbn )
if ISBNPLUSmdt['author'] is not '' and ISBNPLUSmdt['title'] is not '':
add_isbn( db_file_path, os.path.join( path, name ), isbn, ISBNPLUSmdt['author'], ISBNPLUSmdt['title'], 'ISBN+' )
#Close the file
f.close()
......
......@@ -53,6 +53,7 @@ def searchISBNstrings( cnt ):
out = []
pos = cnt.find("ISBN")
while pos != -1 :
old_len=len(out)
if settings.verbosity_level_numeric > 1:
......@@ -60,6 +61,7 @@ def searchISBNstrings( cnt ):
strippedisbn = ''
isbnstr=cnt[pos:pos+40]
for i in range( len(isbnstr) ):
if isbnstr[i].isdigit() :
strippedisbn += isbnstr[i]
......@@ -67,67 +69,67 @@ def searchISBNstrings( cnt ):
if len(strippedisbn) == 9 or ( len(strippedisbn) == 11 and strippedisbn[0:2] == '10' ):#e se e' nella posizione corretta per essere un carattere di controllo ISBN10
strippedisbn += isbnstr[i]
#strippedisbn = re.sub("\D", "", cnt[pos:pos+40]) #Elimina i caratteri che non sono numeri
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\tStripped ISBN:", strippedisbn
if len( strippedisbn ) >= 10: #Se ci sono meno di dieci numeri, boh che cazzo e'?
if strippedisbn[0:2] == '10' and len( strippedisbn ) >= 12: #Puo' essere un ISBN10 con 10 davanti o un ISBN 10 senza il 10 davanti
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\tPenso sia un ISBN10."
if checkISBN10( strippedisbn[2:12] ):
out.append( strippedisbn[2:12] )
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\tAggiunto:\x1b[1m", out[len(out)-1], "\x1b[22m ",
isbnPLUS.printMetadataForISBN( out[len(out)-1] )
OpenLibrary.printMetadataForISBN( out[len(out)-1] )
if settings.verbosity_level_numeric > 1:
print
if checkISBN10( strippedisbn[0:10] ):
out.append( strippedisbn[0:10] )
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\tAggiunto:\x1b[1m", out[len(out)-1], "\x1b[22m ",
isbnPLUS.printMetadataForISBN( out[len(out)-1] )
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."
if checkISBN10( strippedisbn[0:10] ):
out.append( strippedisbn[0:10] )
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\tAggiunto:\x1b[1m", out[len(out)-1], "\x1b[22m ",
isbnPLUS.printMetadataForISBN( out[len(out)-1] )
OpenLibrary.printMetadataForISBN( out[len(out)-1] )
if settings.verbosity_level_numeric > 1:
print
if checkISBN13( strippedisbn[2:15] ):
out.append( strippedisbn[2:15] )
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\tAggiunto:\x1b[1m", out[len(out)-1], "\x1b[22m ",
isbnPLUS.printMetadataForISBN( out[len(out)-1] )
OpenLibrary.printMetadataForISBN( out[len(out)-1] )
if settings.verbosity_level_numeric > 1:
print
else:
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\tNon so se sia un ISBN10 o un ISBN13."
if checkISBN13( strippedisbn[0:13] ):
out.append( strippedisbn[0:13] )
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\tAggiunto:\x1b[1m", out[len(out)-1], "\x1b[22m ",
isbnPLUS.printMetadataForISBN( out[len(out)-1] )
OpenLibrary.printMetadataForISBN( out[len(out)-1] )
if settings.verbosity_level_numeric > 1:
print
if checkISBN10( strippedisbn[0:10] ):
out.append( strippedisbn[0:10] )
if settings.verbosity_level_numeric > 1:
print "\x1b[33m[debug]\x1b[0m\t\tAggiunto:\x1b[1m", out[len(out)-1], "\x1b[22m ",
isbnPLUS.printMetadataForISBN( out[len(out)-1] )
OpenLibrary.printMetadataForISBN( out[len(out)-1] )
if settings.verbosity_level_numeric > 1:
print
if len(out) == old_len:
......@@ -135,6 +137,7 @@ def searchISBNstrings( cnt ):
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 )
return out
def checkISBN10( isbn ):
......
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