Merging changes to book_data.py
This commit is contained in:
commit
734c6870b4
|
@ -5,6 +5,7 @@ except ImportError:
|
||||||
# Fall back to Python 2's urllib2
|
# Fall back to Python 2's urllib2
|
||||||
from urllib2 import urlopen,URLError
|
from urllib2 import urlopen,URLError
|
||||||
from json import loads,dumps
|
from json import loads,dumps
|
||||||
|
from socket import timeout
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
""" Library Book Type Description:
|
""" Library Book Type Description:
|
||||||
|
@ -39,8 +40,10 @@ def openLibrary_isbn(ISBN):
|
||||||
jsondata = urlopen("http://openlibrary.org/api/books"
|
jsondata = urlopen("http://openlibrary.org/api/books"
|
||||||
"?format=json&jscmd=data&bibkeys=ISBN:"+isbn,
|
"?format=json&jscmd=data&bibkeys=ISBN:"+isbn,
|
||||||
timeout=3)
|
timeout=3)
|
||||||
except URLError:
|
except URLError as e:
|
||||||
return {}
|
return {'title':e}
|
||||||
|
except timeout:
|
||||||
|
return {'title':'Timeout while connecting to OpenLibrary.org'}
|
||||||
openBook = loads(jsondata.read().decode('utf-8'))
|
openBook = loads(jsondata.read().decode('utf-8'))
|
||||||
if "ISBN:"+isbn not in openBook:
|
if "ISBN:"+isbn not in openBook:
|
||||||
return {'isbn':isbn,'title':'Book not found'}
|
return {'isbn':isbn,'title':'Book not found'}
|
||||||
|
|
Loading…
Reference in New Issue