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))
|
||||
if key == 'isbn':
|
||||
r = meta.lookup(key, data[key])
|
||||
r = meta.lookup_isbn(data[key])
|
||||
if r:
|
||||
response['items'].append(r)
|
||||
elif key == 'author,title':
|
||||
|
|
|
@ -508,7 +508,7 @@ class Item(db.Model):
|
|||
# FIXME get from user_meta
|
||||
if state.online:
|
||||
if 'isbn' in self.meta:
|
||||
data = meta.lookup('isbn', self.meta['isbn'])
|
||||
data = meta.lookup_isbn(self.meta['isbn'])
|
||||
if data:
|
||||
for key in data:
|
||||
self.meta[key] = data[key]
|
||||
|
|
|
@ -16,16 +16,6 @@ import logging
|
|||
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):
|
||||
results = google.find(title=title, author=author)
|
||||
# results = duckduckgo.find(query)
|
||||
|
@ -36,60 +26,14 @@ def find(title=None, author=None):
|
|||
'''
|
||||
return results
|
||||
|
||||
def lookup_provider(arg):
|
||||
provider, id, ids, key, value = arg
|
||||
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):
|
||||
def lookup_isbn(value):
|
||||
if not isvalid_id('isbn', value):
|
||||
return {}
|
||||
if key == 'isbn':
|
||||
try:
|
||||
data = google.info(value)
|
||||
except:
|
||||
logger.debug('google.info failed %s=%s', key, value, exc_info=True)
|
||||
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)]:
|
||||
if key in data and not isinstance(data[key], list):
|
||||
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')):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in a new issue