fixed some book-lookup stuff
authorJohn Ladan <jladan@uwaterloo.ca>
Thu, 22 Mar 2012 03:19:08 +0000 (23:19 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Thu, 22 Mar 2012 03:19:08 +0000 (23:19 -0400)
bookData.py
bookForm.py

index 8fbe953..516e967 100644 (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'}
index 9671bbc..2b92bbb 100644 (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 {}