remove unused code, only isbn lookup works
This commit is contained in:
parent
33e672c32b
commit
f66e0fbb15
3 changed files with 10 additions and 67 deletions
|
@ -244,7 +244,7 @@ def findMetadata(data):
|
||||||
}
|
}
|
||||||
key = ','.join(sorted(data))
|
key = ','.join(sorted(data))
|
||||||
if key == 'isbn':
|
if key == 'isbn':
|
||||||
r = meta.lookup(key, data[key])
|
r = meta.lookup_isbn(data[key])
|
||||||
if r:
|
if r:
|
||||||
response['items'].append(r)
|
response['items'].append(r)
|
||||||
elif key == 'author,title':
|
elif key == 'author,title':
|
||||||
|
|
|
@ -508,7 +508,7 @@ class Item(db.Model):
|
||||||
# FIXME get from user_meta
|
# FIXME get from user_meta
|
||||||
if state.online:
|
if state.online:
|
||||||
if 'isbn' in self.meta:
|
if 'isbn' in self.meta:
|
||||||
data = meta.lookup('isbn', self.meta['isbn'])
|
data = meta.lookup_isbn(self.meta['isbn'])
|
||||||
if data:
|
if data:
|
||||||
for key in data:
|
for key in data:
|
||||||
self.meta[key] = data[key]
|
self.meta[key] = data[key]
|
||||||
|
|
|
@ -16,16 +16,6 @@ import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
providers = [
|
|
||||||
('openlibrary', 'olid'),
|
|
||||||
('loc', 'lccn'),
|
|
||||||
('worldcat', 'oclc'),
|
|
||||||
('worldcat', 'isbn'),
|
|
||||||
('lookupbyisbn', 'asin'),
|
|
||||||
('lookupbyisbn', 'isbn'),
|
|
||||||
('abebooks', 'isbn')
|
|
||||||
]
|
|
||||||
|
|
||||||
def find(title=None, author=None):
|
def find(title=None, author=None):
|
||||||
results = google.find(title=title, author=author)
|
results = google.find(title=title, author=author)
|
||||||
# results = duckduckgo.find(query)
|
# results = duckduckgo.find(query)
|
||||||
|
@ -36,60 +26,14 @@ def find(title=None, author=None):
|
||||||
'''
|
'''
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def lookup_provider(arg):
|
def lookup_isbn(value):
|
||||||
provider, id, ids, key, value = arg
|
if not isvalid_id('isbn', value):
|
||||||
values = set()
|
|
||||||
for key, value in ids:
|
|
||||||
if key == id or provider in ('openlibrary', ):
|
|
||||||
for kv in globals()[provider].get_ids(key, value):
|
|
||||||
values.add(kv)
|
|
||||||
return values
|
|
||||||
|
|
||||||
def lookup(key, value):
|
|
||||||
if not isvalid_id(key, value):
|
|
||||||
return {}
|
return {}
|
||||||
if key == 'isbn':
|
|
||||||
try:
|
try:
|
||||||
data = google.info(value)
|
data = google.info(value)
|
||||||
except:
|
except:
|
||||||
logger.debug('google.info failed %s=%s', key, value, exc_info=True)
|
logger.debug('google.info failed %s=%s', key, value, exc_info=True)
|
||||||
data = {}
|
data = {}
|
||||||
else:
|
|
||||||
data = {key: [value]}
|
|
||||||
ids = set([(key, value)])
|
|
||||||
provider_data = {}
|
|
||||||
done = False
|
|
||||||
|
|
||||||
while not done:
|
|
||||||
done = True
|
|
||||||
for provider, id in providers:
|
|
||||||
result = lookup_provider((provider, id, ids, key, value))
|
|
||||||
done = not result - ids
|
|
||||||
ids.update(result)
|
|
||||||
logger.debug('FIXME: sort ids')
|
|
||||||
ids = sorted(ids, key=lambda i: ox.sort_string(''.join(i)))
|
|
||||||
logger.debug('IDS %s', ids)
|
|
||||||
for k, v in ids:
|
|
||||||
for provider, id in providers:
|
|
||||||
if id == k:
|
|
||||||
if provider not in provider_data:
|
|
||||||
provider_data[provider] = {}
|
|
||||||
for k_, v_ in globals()[provider].lookup(v).items():
|
|
||||||
if k_ not in provider_data[provider]:
|
|
||||||
provider_data[provider][k_] = v_
|
|
||||||
for provider in sorted(
|
|
||||||
list(provider_data.keys()),
|
|
||||||
key=lambda x: -len(provider_data[x])
|
|
||||||
):
|
|
||||||
logger.debug('%s %s %s', provider, len(provider_data[provider]), list(provider_data[provider].keys()))
|
|
||||||
for k_, v_ in provider_data[provider].items():
|
|
||||||
if not k_ in data:
|
|
||||||
data[k_] = v_
|
|
||||||
for k, v in ids:
|
|
||||||
if k not in data:
|
|
||||||
data[k] = []
|
|
||||||
if v not in data[k]:
|
|
||||||
data[k].append(v)
|
|
||||||
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
|
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
|
||||||
if key in data and not isinstance(data[key], list):
|
if key in data and not isinstance(data[key], list):
|
||||||
data[key] = [data[key]]
|
data[key] = [data[key]]
|
||||||
|
@ -105,4 +49,3 @@ def isvalid_id(key, value):
|
||||||
if key == 'olid' and not (value.startswith('OL') and value.endswith('M')):
|
if key == 'olid' and not (value.startswith('OL') and value.endswith('M')):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue