optionally send api key

This commit is contained in:
j 2016-01-25 16:38:57 +05:30
parent c03f72b47c
commit b5be527aca

View file

@ -8,6 +8,7 @@ import ox.web.google
import stdnum.isbn import stdnum.isbn
from .utils import find_isbns, get_language, decode_html_data, to_isbn13 from .utils import find_isbns, get_language, decode_html_data, to_isbn13
import settings
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -40,6 +41,9 @@ def info(key, value):
if key not in ('isbn', 'lccn', 'oclc'): if key not in ('isbn', 'lccn', 'oclc'):
raise IOError('unknwon key %s' % key) raise IOError('unknwon key %s' % key)
url = 'https://www.googleapis.com/books/v1/volumes?q=%s:%s' % (key, value) url = 'https://www.googleapis.com/books/v1/volumes?q=%s:%s' % (key, value)
api_key = settings.server.get('google_api_key')
if api_key:
url += '&key=' + api_key
if api_limit.error: if api_limit.error:
raise IOError(url) raise IOError(url)
while not api_limit.consume(1): while not api_limit.consume(1):