Fixed bug {22} where isbn was not correctly parsed
This commit is contained in:
parent
6d112dd1c2
commit
6f840f1073
|
@ -12,9 +12,6 @@ from fileformat import *
|
||||||
from util import *
|
from util import *
|
||||||
|
|
||||||
exit_commands = ['exit', 'abort', 'quit', 'bye', 'eat flaming death', 'q']
|
exit_commands = ['exit', 'abort', 'quit', 'bye', 'eat flaming death', 'q']
|
||||||
|
|
||||||
comments = ""
|
|
||||||
|
|
||||||
encoding = 'utf8'
|
encoding = 'utf8'
|
||||||
|
|
||||||
# midlertidig
|
# midlertidig
|
||||||
|
@ -31,7 +28,8 @@ def suggest_book(dbconnection, tmp_file=False):
|
||||||
filler = ' -------------------------------------------------- '
|
filler = ' -------------------------------------------------- '
|
||||||
print("# Enter ISBN number(s), end with eof <CTRL+D>")
|
print("# Enter ISBN number(s), end with eof <CTRL+D>")
|
||||||
for ISBN in sys.stdin:
|
for ISBN in sys.stdin:
|
||||||
if ISBN.strip() in exit_commands:
|
ISBN = ISBN.strip()
|
||||||
|
if ISBN in exit_commands:
|
||||||
print("aborted")
|
print("aborted")
|
||||||
break
|
break
|
||||||
elif book_in_db(dbconnection, ISBN):
|
elif book_in_db(dbconnection, ISBN):
|
||||||
|
@ -107,14 +105,17 @@ def build_book(entry, authors, indata=False):
|
||||||
|
|
||||||
isbn = find_isbn(unicode(dic['identifiers']))
|
isbn = find_isbn(unicode(dic['identifiers']))
|
||||||
if isbn:
|
if isbn:
|
||||||
book['isbn'] = unicode(isbn)
|
book['isbn'] = unicode(isbn)
|
||||||
elif indata:
|
elif indata:
|
||||||
if len(indata) == 13:
|
if len(indata) == 13:
|
||||||
book['isbn'] = unicode(indata)
|
book['isbn'] = unicode(indata)
|
||||||
|
else:
|
||||||
|
print("!!!isbn length not 13")
|
||||||
else:
|
else:
|
||||||
comment("No ISBN found.")
|
#comment("No ISBN found.")
|
||||||
return False
|
print("No ISBN found.")
|
||||||
|
return False
|
||||||
|
|
||||||
book['title'] = unicode(entry.dc_title[0].text, encoding)
|
book['title'] = unicode(entry.dc_title[0].text, encoding)
|
||||||
|
|
||||||
set_value(book, dic, 'category')
|
set_value(book, dic, 'category')
|
||||||
|
@ -142,11 +143,8 @@ def build_book(entry, authors, indata=False):
|
||||||
book['references'] = {}
|
book['references'] = {}
|
||||||
book['references']['google-books'] = [unicode(dic['preview'], encoding)]
|
book['references']['google-books'] = [unicode(dic['preview'], encoding)]
|
||||||
|
|
||||||
return book
|
|
||||||
|
|
||||||
def comment(comm):
|
return book
|
||||||
global comments
|
|
||||||
comments += u'%s\n' % comm
|
|
||||||
|
|
||||||
def set_value(book, dic, key):
|
def set_value(book, dic, key):
|
||||||
if key in dic:
|
if key in dic:
|
||||||
|
@ -211,48 +209,6 @@ def build_author(new_author):
|
||||||
return author
|
return author
|
||||||
|
|
||||||
|
|
||||||
# deprecated
|
|
||||||
def build_authors(dbconnection, dictionary):
|
|
||||||
if 'authors' in dictionary:
|
|
||||||
author_list = []
|
|
||||||
for author in dictionary['authors']:
|
|
||||||
author_list.append(get_or_create_author(dbconnection, author))
|
|
||||||
return author_list
|
|
||||||
else:
|
|
||||||
comment("No authors found.")
|
|
||||||
return []
|
|
||||||
|
|
||||||
# deprecated
|
|
||||||
def get_or_create_author(dbconnection, author_name):
|
|
||||||
author = {}
|
|
||||||
author['action'] = 'new-person'
|
|
||||||
names = author_name.split()
|
|
||||||
first = ' '.join(names[:-1])
|
|
||||||
last = names[-1]
|
|
||||||
author['first_name'] = first
|
|
||||||
author['last_name'] = last
|
|
||||||
|
|
||||||
cursor = dbconnection.cursor()
|
|
||||||
query = "SELECT id FROM person WHERE lastname=%(last)s OR firstname=%(first)s"
|
|
||||||
cursor.execute(query, {'last':last, 'first':first} )
|
|
||||||
candidates = fetchall_dict(cursor)
|
|
||||||
|
|
||||||
if len(candidates) == 1:
|
|
||||||
return candidates[0]
|
|
||||||
if len(candidates) > 1:
|
|
||||||
# TODO: TEST
|
|
||||||
print("Found several candidates:")
|
|
||||||
for i in range(candidates):
|
|
||||||
print "%d: %s" % (i,
|
|
||||||
feed.entry[i].dc_title[0].text)
|
|
||||||
candno = (int)(raw_input("Which candidate do you want? [0-%d] " % (len(candidates) - 1)))
|
|
||||||
return candidates[candno]
|
|
||||||
else:
|
|
||||||
print("No candidate found for " + author_name + ", making new person")
|
|
||||||
newid = ''.join([i[0] for i in names]).lower()
|
|
||||||
# Check if id already exists
|
|
||||||
|
|
||||||
|
|
||||||
#Cargo-cult coded function to unescape special XML characters
|
#Cargo-cult coded function to unescape special XML characters
|
||||||
|
|
||||||
def select_from_list(list, attributes=False, item_name=""):
|
def select_from_list(list, attributes=False, item_name=""):
|
||||||
|
@ -290,5 +246,5 @@ def unescape(s):
|
||||||
es = u""
|
es = u""
|
||||||
return es.join(list)
|
return es.join(list)
|
||||||
|
|
||||||
|
# remove me
|
||||||
suggest_book(connection, tmp_file=True)
|
suggest_book(connection, tmp_file=True)
|
||||||
|
|
Reference in New Issue