Fixed bug {22} where isbn was not correctly parsed

This commit is contained in:
Andreas Lindahl Flåten 2011-10-09 13:32:11 +00:00
parent 6d112dd1c2
commit 6f840f1073

View File

@ -12,9 +12,6 @@ from fileformat import *
from util import *
exit_commands = ['exit', 'abort', 'quit', 'bye', 'eat flaming death', 'q']
comments = ""
encoding = 'utf8'
# midlertidig
@ -31,7 +28,8 @@ def suggest_book(dbconnection, tmp_file=False):
filler = ' -------------------------------------------------- '
print("# Enter ISBN number(s), end with eof <CTRL+D>")
for ISBN in sys.stdin:
if ISBN.strip() in exit_commands:
ISBN = ISBN.strip()
if ISBN in exit_commands:
print("aborted")
break
elif book_in_db(dbconnection, ISBN):
@ -107,14 +105,17 @@ def build_book(entry, authors, indata=False):
isbn = find_isbn(unicode(dic['identifiers']))
if isbn:
book['isbn'] = unicode(isbn)
book['isbn'] = unicode(isbn)
elif indata:
if len(indata) == 13:
book['isbn'] = unicode(indata)
if len(indata) == 13:
book['isbn'] = unicode(indata)
else:
print("!!!isbn length not 13")
else:
comment("No ISBN found.")
return False
#comment("No ISBN found.")
print("No ISBN found.")
return False
book['title'] = unicode(entry.dc_title[0].text, encoding)
set_value(book, dic, 'category')
@ -142,11 +143,8 @@ def build_book(entry, authors, indata=False):
book['references'] = {}
book['references']['google-books'] = [unicode(dic['preview'], encoding)]
return book
def comment(comm):
global comments
comments += u'%s\n' % comm
return book
def set_value(book, dic, key):
if key in dic:
@ -211,48 +209,6 @@ def build_author(new_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
def select_from_list(list, attributes=False, item_name=""):
@ -290,5 +246,5 @@ def unescape(s):
es = u""
return es.join(list)
# remove me
suggest_book(connection, tmp_file=True)