beginnings of retrieving book data from openLibrary
[public/library.git] / bookData.py
1 from urllib2 import urlopen
2 from json import load,dumps
3
4 def openLibrary(isbn):
5     jsondata = urlopen("http://openlibrary.org/api/books?format=json&jscmd=data&bibkeys=ISBN:"+isbn)
6     book = load(jsondata)
7     if len(book)==0:
8         return book
9     else:
10         return book["ISBN:"+isbn]
11
12 book = openLibrary("9780521714723")
13 if "title" in book: print book["title"]
14 if "subjects" in book: print dumps(book["subjects"], indent=2)
15 book = openLibrary("9780521565431")
16 if "title" in book: print book["title"]
17 if "subjects" in book: print dumps(book["subjects"], indent=2)
18 book = openLibrary("689145728392")
19 if "title" in book: print book["title"]
20 if "subjects" in book: print dumps(book["subjects"], indent=2)
21 book = openLibrary("9780321468932")
22 if "title" in book: print book["title"]
23 if "subjects" in book: print dumps(book["subjects"], indent=2)
24 book = openLibrary("9781555580414")
25 if "title" in book: print book["title"]
26 if "subjects" in book: print dumps(book["subjects"], indent=2)