2014-05-16 08:06:11 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
from __future__ import division
|
|
|
|
|
|
|
|
import ox.web.google
|
|
|
|
import stdnum.isbn
|
|
|
|
|
|
|
|
from .utils import find_isbns
|
|
|
|
|
2014-05-17 14:26:59 +00:00
|
|
|
import logging
|
|
|
|
logger = logging.getLogger('meta.google')
|
|
|
|
|
2014-05-16 08:06:11 +00:00
|
|
|
|
2014-05-21 00:02:21 +00:00
|
|
|
def find(query):
|
|
|
|
logger.debug('find %s', query)
|
2014-05-16 08:06:11 +00:00
|
|
|
query += ' isbn'
|
|
|
|
isbns = []
|
|
|
|
for r in ox.web.google.find(query):
|
|
|
|
isbns += find_isbns(' '.join(r))
|
2014-05-17 14:26:59 +00:00
|
|
|
logger.debug('isbns', isbns)
|
2014-05-16 08:06:11 +00:00
|
|
|
results = []
|
|
|
|
done = set()
|
|
|
|
for isbn in isbns:
|
|
|
|
if isbn not in done:
|
|
|
|
r = {
|
2014-05-21 00:02:21 +00:00
|
|
|
'isbn': isbn,
|
|
|
|
'primaryid': ['isbn', isbn]
|
2014-05-16 08:06:11 +00:00
|
|
|
}
|
|
|
|
results.append(r)
|
|
|
|
done.add(isbn)
|
|
|
|
if len(isbn) == 10:
|
|
|
|
done.add(stdnum.isbn.to_isbn13(isbn))
|
2014-05-21 00:02:21 +00:00
|
|
|
if len(isbn) == 13 and isbn.startswith('978'):
|
2014-05-17 09:19:32 +00:00
|
|
|
done.add(stdnum.isbn.to_isbn10(isbn))
|
2014-05-16 08:06:11 +00:00
|
|
|
return results
|