started creation of book info format
authorJohn Ladan <jladan@uwaterloo.ca>
Sun, 11 Mar 2012 07:40:14 +0000 (03:40 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Sun, 11 Mar 2012 07:40:14 +0000 (03:40 -0400)
bookData.py

index a52e692..a3c539a 100644 (file)
@@ -3,24 +3,22 @@ from json import load,dumps
 
 def openLibrary(isbn):
     jsondata = urlopen("http://openlibrary.org/api/books?format=json&jscmd=data&bibkeys=ISBN:"+isbn)
-    book = load(jsondata)
-    if len(book)==0:
-        return book
-    else:
-        return book["ISBN:"+isbn]
+    openBook = load(jsondata)
+    if "ISBN:"+isbn not in openBook:
+        return openBook
+    openBook = openBook["ISBN:"+isbn]
+    # create my custom dict for books with the info we want.
+    book = {"isbn" : isbn}
+    book['title']=openbook['title']
+    # continue with the rest later
 
 book = openLibrary("9780521714723")
-if "title" in book: print book["title"]
-if "subjects" in book: print dumps(book["subjects"], indent=2)
+print dumps(book, indent=2)
 book = openLibrary("9780521565431")
-if "title" in book: print book["title"]
-if "subjects" in book: print dumps(book["subjects"], indent=2)
+print dumps(book, indent=2)
 book = openLibrary("689145728392")
-if "title" in book: print book["title"]
-if "subjects" in book: print dumps(book["subjects"], indent=2)
+print dumps(book, indent=2)
 book = openLibrary("9780321468932")
-if "title" in book: print book["title"]
-if "subjects" in book: print dumps(book["subjects"], indent=2)
+print dumps(book, indent=2)
 book = openLibrary("9781555580414")
-if "title" in book: print book["title"]
-if "subjects" in book: print dumps(book["subjects"], indent=2)
+print dumps(book, indent=2)