Commit ad60a422 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

ISNBMetadata utility revised to use Internet Archive's OpenLibrary, rather...

ISNBMetadata utility revised to use Internet Archive's OpenLibrary, rather than WorldCat, which is now a paid service
parent cff995c1
# standard libary imports
from datetime import datetime
# third party imports
import requests
# imports from your apps
from .models import Flag, Rating, BidFlag
# pulls worldcat metadata from ISBNs
# previously pulled worldcat metadata from ISBNs, worldcat is now a paid service
# thankfully, the internet archive has stepped in with a free api replacement
def ISBNMetadata(standardISBN):
# passing in numbers starting with 0 throws "SyntaxError: invalid token"
url = "" +\
str(standardISBN) +\
# supports both ISBN 10 and ISBN 13
key_format = 'ISBN:%s' % str(standardISBN)
url = "" +\
key_format +\
# In case the API fails to return, simply return None.
......@@ -16,10 +22,28 @@ def ISBNMetadata(standardISBN):
return None
# format into a dictionary
dejson = metadata.json()
json_response = metadata.json()
isbn_data = json_response.get(key_format)
metadataDict = dejson.get('list')
return metadataDict[0]
title = isbn_data.get('title', '')
subtitle = isbn_data.get('subtitle', '')
if subtitle:
full_title = '%s: %s' % (title, subtitle)
full_title = title
metadataDict = {'title': full_title}
date = isbn_data.get('publish_date' ,'')
# unfortunately, dates are formatted in a variety of different ways
# but year should be the final four digits regardless of, say, month formatting
metadataDict['year'] = date[-4:]
authors = isbn_data.get('authors', 'wat')
metadataDict['authors'] = ' and '.join([author.get('name', '')
for author in authors])
# unlike worldcat, openlibrary does not provide edition information
return metadataDict
return None
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment