beginnings of retrieving book data from openLibrary
authorJohn Ladan <jladan@uwaterloo.ca>
Sun, 11 Mar 2012 07:11:40 +0000 (03:11 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Sun, 11 Mar 2012 07:11:40 +0000 (03:11 -0400)
bookData.py [new file with mode: 0644]

diff --git a/bookData.py b/bookData.py
new file mode 100644 (file)
index 0000000..a52e692
--- /dev/null
@@ -0,0 +1,26 @@
+from urllib2 import urlopen
+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]
+
+book = openLibrary("9780521714723")
+if "title" in book: print book["title"]
+if "subjects" in book: print dumps(book["subjects"], indent=2)
+book = openLibrary("9780521565431")
+if "title" in book: print book["title"]
+if "subjects" in book: print dumps(book["subjects"], indent=2)
+book = openLibrary("689145728392")
+if "title" in book: print book["title"]
+if "subjects" in book: print dumps(book["subjects"], indent=2)
+book = openLibrary("9780321468932")
+if "title" in book: print book["title"]
+if "subjects" in book: print dumps(book["subjects"], indent=2)
+book = openLibrary("9781555580414")
+if "title" in book: print book["title"]
+if "subjects" in book: print dumps(book["subjects"], indent=2)