2013-10-11 17:28:32 +00:00
|
|
|
from ox.cache import read_url
|
|
|
|
from ox.utils import json
|
|
|
|
|
|
|
|
def find(query):
|
|
|
|
url = 'http://openlibrary.org/search.json?q=%s' % query
|
|
|
|
print url
|
|
|
|
data = json.loads(read_url(url))
|
|
|
|
return data
|
2014-08-12 08:44:01 +00:00
|
|
|
|
|
|
|
def authors_ol(authors):
|
|
|
|
r = []
|
|
|
|
for a in authors:
|
|
|
|
url = 'http://openlibrary.org%s.json' % a
|
|
|
|
data = json.loads(read_url(url))
|
|
|
|
r.append(data['name'])
|
|
|
|
return r
|
|
|
|
|
|
|
|
def get_data(isbn):
|
|
|
|
data = {}
|
|
|
|
ol = find(isbn)
|
|
|
|
if ol['docs']:
|
|
|
|
d = ol['docs'][0]
|
|
|
|
data['title'] = d['title']
|
|
|
|
data['author'] = authors_ol(d['authors'])
|
|
|
|
data['work'] = d['key']
|
|
|
|
data['edition'] = d['edition_key'][0]
|
|
|
|
url = 'https://openlibrary.org/books/%s.json' % data['edition']
|
|
|
|
info = json.load(read_url(url))
|
|
|
|
data['pages'] = info['number_of_pages']
|
|
|
|
if 'dewey_decimal_class' in info:
|
|
|
|
data['classification'] = info['dewey_decimal_class'][0]
|
|
|
|
return data
|