fixed some book-lookup stuff

jessie
John Ladan 2012-03-21 23:19:08 -04:00
parent fdc04b9aa0
commit b363e70b5e
2 changed files with 7 additions and 3 deletions

View File

@ -1,4 +1,4 @@
from urllib2 import urlopen
from urllib2 import urlopen,URLError
from json import load,dumps
""" Library Book Type Description:
@ -29,7 +29,10 @@ Keys:
# look up data from openlibrary.org using isbn
def openLibrary(ISBN):
isbn = str(ISBN)
jsondata = urlopen("http://openlibrary.org/api/books?format=json&jscmd=data&bibkeys=ISBN:"+isbn)
try:
jsondata = urlopen("http://openlibrary.org/api/books?format=json&jscmd=data&bibkeys=ISBN:"+isbn, timeout=3)
except URLError:
return {}
openBook = load(jsondata)
if "ISBN:"+isbn not in openBook:
return {'isbn':isbn,'title':'Book not found'}

View File

@ -179,7 +179,8 @@ class bookForm:
elif ch==10 or ch==curses.KEY_ENTER:
if self.hl==0:
book = self.lookup(self.entries[0])
self.updateEntries(book)
if book != {}:
self.updateEntries(book)
self.refresh()
elif self.bt==0:
return {}