deletion of categories now supported
[library/.git] / bookData.py
index 8e10054..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:
@@ -17,7 +17,7 @@ Keys:
     publish date - string of date (to make things easier to code/catalogue (won't be stored)
     publish year - int (this kind of thing will have to be confirmed by cataloguer)
     publish month - int
-    publish locations - like publishers
+    publish location - like publisher
     
     pages - integer - just the number of pages
     pagination - string eg. "xviii, 1327-1850"
@@ -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'}
@@ -48,10 +51,10 @@ def openLibrary(ISBN):
             book["publisher"] += "; " + v['name']
         book['publisher'] = book['publisher'][2:]
     if "publish_places" in openBook:
-        book["publish locations"]=""
+        book["publish location"]=""
         for v in openBook["publish_places"]:
-            book["publish locations"] += "; " + v['name']
-        book['publish locations'] = book['publish locations'][2:]
+            book["publish location"] += "; " + v['name']
+        book['publish location'] = book['publish location'][2:]
 
     # for lccn, there maybe be multiple values in the query. I'm just taking the first, but the full list may be useful
     if "lccn" in openBook['identifiers']: