minor formatting changes

pull/1/head
Ed Summers 2012-01-17 23:22:07 -05:00
parent 23c3758e84
commit db576571bb
1 changed files with 17 additions and 17 deletions

View File

@ -14,10 +14,10 @@ import regluit.core.isbn
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def add_by_oclc(isbn, work=None): def add_by_oclc(isbn, work=None):
# this is indirection in case we have a data source other than google # this is indirection in case we have a data source other than google
return add_by_oclc_from_google(isbn) return add_by_oclc_from_google(isbn)
def add_by_oclc_from_google(oclc): def add_by_oclc_from_google(oclc):
@ -36,7 +36,7 @@ def add_by_oclc_from_google(oclc):
return None return None
try: try:
e=add_by_googlebooks_id(results['items'][0]['id'], results=results['items'][0]) e = add_by_googlebooks_id(results['items'][0]['id'], results=results['items'][0])
models.Identifier(type='oclc', value=oclc, edition=e, work=e.work).save() models.Identifier(type='oclc', value=oclc, edition=e, work=e.work).save()
return e return e
except LookupFailure, e: except LookupFailure, e:
@ -48,7 +48,7 @@ def add_by_oclc_from_google(oclc):
def add_by_isbn(isbn, work=None): def add_by_isbn(isbn, work=None):
if not isbn: if not isbn:
return None return None
e=add_by_isbn_from_google(isbn, work=work) e = add_by_isbn_from_google(isbn, work=work)
if e: if e:
return e return e
@ -62,20 +62,20 @@ def add_by_isbn(isbn, work=None):
# forget it! # forget it!
try: try:
isbn=regluit.core.isbn.ISBN(isbn) isbn = regluit.core.isbn.ISBN(isbn)
except: except:
logger.exception("invalid isbn: %s", isbn) logger.exception("invalid isbn: %s", isbn)
return None return None
if not isbn.valid: if not isbn.valid:
return None return None
isbn=isbn.to_string() isbn = isbn.to_string()
# we don't know the language ->'xx' # we don't know the language ->'xx'
w= models.Work(title=work.title, language='xx') w = models.Work(title=work.title, language='xx')
w.save() w.save()
e= models.Edition(title=work.title,work=w) e = models.Edition(title=work.title,work=w)
e.save() e.save()
e.new=True e.new = True
models.Identifier(type='isbn', value=isbn, work=w, edition=e).save() models.Identifier(type='isbn', value=isbn, work=w, edition=e).save()
return e return e
@ -88,7 +88,7 @@ def add_by_isbn_from_google(isbn, work=None):
if not isbn: if not isbn:
return None return None
if len(isbn)==10: if len(isbn)==10:
isbn=regluit.core.isbn.convert_10_to_13(isbn) isbn = regluit.core.isbn.convert_10_to_13(isbn)
logger.info("adding book by isbn %s", isbn) logger.info("adding book by isbn %s", isbn)
# check if we already have this isbn # check if we already have this isbn
@ -154,11 +154,11 @@ def add_by_googlebooks_id(googlebooks_id, work=None, results=None):
if work and work.language != language: if work and work.language != language:
logger.info("not connecting %s since it is %s instead of %s" % logger.info("not connecting %s since it is %s instead of %s" %
(googlebooks_id, language, work.language)) (googlebooks_id, language, work.language))
work=None work = None
isbn = None isbn = None
for i in d.get('industryIdentifiers', []): for i in d.get('industryIdentifiers', []):
if i['type'] == 'ISBN_10' and not isbn: if i['type'] == 'ISBN_10' and not isbn:
isbn= regluit.core.isbn.convert_10_to_13(i['identifier']) isbn = regluit.core.isbn.convert_10_to_13(i['identifier'])
elif i['type'] == 'ISBN_13': elif i['type'] == 'ISBN_13':
isbn = i['identifier'] isbn = i['identifier']
@ -167,7 +167,7 @@ def add_by_googlebooks_id(googlebooks_id, work=None, results=None):
work = get_work_by_id(type='isbn',value=isbn) work = get_work_by_id(type='isbn',value=isbn)
if not work: if not work:
work = models.Work.objects.create(title=d['title'], language=language) work = models.Work.objects.create(title=d['title'], language=language)
work.new=True work.new = True
work.save() work.save()
@ -178,7 +178,7 @@ def add_by_googlebooks_id(googlebooks_id, work=None, results=None):
e.publisher = d.get('publisher') e.publisher = d.get('publisher')
e.publication_date = d.get('publishedDate', '') e.publication_date = d.get('publishedDate', '')
e.save() e.save()
e.new=True e.new = True
# create identifier where needed # create identifier where needed
models.Identifier(type='goog',value=googlebooks_id,edition=e,work=work).save() models.Identifier(type='goog',value=googlebooks_id,edition=e,work=work).save()
@ -224,11 +224,11 @@ def add_related(isbn):
for other_isbn in thingisbn(isbn): for other_isbn in thingisbn(isbn):
# 979's come back as 13 # 979's come back as 13
if len(other_isbn)==10: if len(other_isbn)==10:
other_isbn=regluit.core.isbn.convert_10_to_13(other_isbn) other_isbn = regluit.core.isbn.convert_10_to_13(other_isbn)
related_edition = add_by_isbn(other_isbn, work=work) related_edition = add_by_isbn(other_isbn, work=work)
if related_edition: if related_edition:
related_language=related_edition.work.language related_language = related_edition.work.language
if edition.work.language == related_language: if edition.work.language == related_language:
new_editions.append(related_edition) new_editions.append(related_edition)
if related_edition.work != edition.work: if related_edition.work != edition.work:
@ -275,7 +275,7 @@ def merge_works(w1, w2):
campaign.work = w1 campaign.work = w1
campaign.save() campaign.save()
for wishlist in models.Wishlist.objects.filter(works__in=[w2]): for wishlist in models.Wishlist.objects.filter(works__in=[w2]):
w2source=wishlist.work_source(w2) w2source = wishlist.work_source(w2)
wishlist.remove_work(w2) wishlist.remove_work(w2)
wishlist.add_work(w1, w2source) wishlist.add_work(w1, w2source)
# TODO: should we decommission w2 instead of deleting it, so that we can # TODO: should we decommission w2 instead of deleting it, so that we can
@ -338,7 +338,7 @@ def _get_json(url, params={}, type='gb'):
headers = {'User-Agent': settings.USER_AGENT, headers = {'User-Agent': settings.USER_AGENT,
'Accept': 'application/json', 'Accept': 'application/json',
'X-Forwarded-For': '69.174.114.214'} 'X-Forwarded-For': '69.174.114.214'}
if type=='gb': if type == 'gb':
params['key'] = settings.GOOGLE_BOOKS_API_KEY params['key'] = settings.GOOGLE_BOOKS_API_KEY
response = requests.get(url, params=params, headers=headers) response = requests.get(url, params=params, headers=headers)
if response.status_code == 200: if response.status_code == 200: