Workaround xisbn sometimes returning incomplete isbn pools

This commit is contained in:
Kovid Goyal 2011-06-16 09:48:08 -06:00
parent 16ca0fa068
commit 5e914a5a20
2 changed files with 12 additions and 4 deletions

View File

@ -85,7 +85,11 @@ class ISBNMerge(object):
isbns, min_year = xisbn.get_isbn_pool(isbn) isbns, min_year = xisbn.get_isbn_pool(isbn)
if not isbns: if not isbns:
isbns = frozenset([isbn]) isbns = frozenset([isbn])
self.pools[isbns] = pool = (min_year, []) if isbns in self.pools:
# xISBN had a brain fart
pool = self.pools[isbn]
else:
self.pools[isbns] = pool = (min_year, [])
if not self.pool_has_result_from_same_source(pool, result): if not self.pool_has_result_from_same_source(pool, result):
pool[1].append(result) pool[1].append(result)

View File

@ -45,6 +45,11 @@ class xISBN(object):
ans.append(rec) ans.append(rec)
return ans return ans
def isbns_in_data(self, data):
for rec in data:
for i in rec.get('isbn', []):
yield i
def get_data(self, isbn): def get_data(self, isbn):
isbn = self.purify(isbn) isbn = self.purify(isbn)
with self.lock: with self.lock:
@ -57,9 +62,8 @@ class xISBN(object):
data = [] data = []
id_ = len(self._data) id_ = len(self._data)
self._data.append(data) self._data.append(data)
for rec in data: for i in self.isbns_in_data(data):
for i in rec.get('isbn', []): self._map[i] = id_
self._map[i] = id_
self._map[isbn] = id_ self._map[isbn] = id_
return self._data[self._map[isbn]] return self._data[self._map[isbn]]