fail better
This commit is contained in:
parent
7e37713c95
commit
5ecb2aeafc
3 changed files with 10 additions and 3 deletions
|
@ -19,7 +19,7 @@ def get_ids(key, value):
|
||||||
ids = []
|
ids = []
|
||||||
if key == 'isbn':
|
if key == 'isbn':
|
||||||
url = 'http://www.loc.gov/search/?q=%s&all=true' % value
|
url = 'http://www.loc.gov/search/?q=%s&all=true' % value
|
||||||
html = ox.cache.read_url(url).decode('utf-8')
|
html = ox.cache.read_url(url).decode('utf-8', 'ignore')
|
||||||
match = re.search('"http://lccn.loc.gov/(\d+)"', html)
|
match = re.search('"http://lccn.loc.gov/(\d+)"', html)
|
||||||
if match:
|
if match:
|
||||||
ids.append(('lccn', match.group(1)))
|
ids.append(('lccn', match.group(1)))
|
||||||
|
|
|
@ -164,9 +164,15 @@ class API(object):
|
||||||
data[key] = json.dumps(data[key])
|
data[key] = json.dumps(data[key])
|
||||||
url = self.base + '/' + action + '?' + urlencode(data)
|
url = self.base + '/' + action + '?' + urlencode(data)
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
result = json.loads(read_url(url).decode('utf-8'))
|
r = read_url(url).decode('utf-8')
|
||||||
|
if '504 Gateway Time-out' in r:
|
||||||
|
r = read_url(url, timeout=-1).decode('utf-8')
|
||||||
|
result = json.loads(r)
|
||||||
else:
|
else:
|
||||||
result = json.loads(read_url(url, timeout=timeout).decode('utf-8'))
|
r = read_url(url, timeout).decode('utf-8')
|
||||||
|
if '504 Gateway Time-out' in r:
|
||||||
|
r = read_url(url, timeout=-1).decode('utf-8')
|
||||||
|
result = json.loads(r)
|
||||||
if 'status' in result and result['status'] == 'error' or 'error' in result:
|
if 'status' in result and result['status'] == 'error' or 'error' in result:
|
||||||
logger.info('FAILED %s %s', action, data)
|
logger.info('FAILED %s %s', action, data)
|
||||||
logger.info('URL %s', url)
|
logger.info('URL %s', url)
|
||||||
|
|
|
@ -50,6 +50,7 @@ def getMetadata(data):
|
||||||
key, value = next(iter(data.items()))
|
key, value = next(iter(data.items()))
|
||||||
if key == 'isbn':
|
if key == 'isbn':
|
||||||
value = utils.normalize_isbn(value)
|
value = utils.normalize_isbn(value)
|
||||||
|
logger.debug('getMetadata key=%s value=%s', key, value)
|
||||||
response = meta.lookup(key, value)
|
response = meta.lookup(key, value)
|
||||||
if response:
|
if response:
|
||||||
response['primaryid'] = [key, value]
|
response['primaryid'] = [key, value]
|
||||||
|
|
Loading…
Reference in a new issue