diff --git a/index.js b/index.js index ba5a69c..ddc5c51 100644 --- a/index.js +++ b/index.js @@ -111,11 +111,12 @@ function insertRow(auth) { field: 'isbn', lang: 'en' }, function(error, results) { - if ( ! error && results.length > 0) { + if ( ! error && results.length > 0 ) { + console.log(results[0]); var book = normalizeGoogleData(results[0]); console.log(book); appendToSheet(auth, _.values(book)); - } else if ( results.length == 0) { + } else if ( results.length == 0 ) { console.log("no book found"); inputLoop(auth); } else { @@ -126,12 +127,16 @@ function insertRow(auth) { } function normalizeGoogleData(book) { - var normalized = { + return { title: book.subtitle ? book.title + ': ' + book.subtitle : book.title, author: _.join(book.authors, ', '), - authorLast: _.lowerCase(_.reverse(_.split(book.authors[0], ' '))[0]), - "isbn-10": _.find(book.industryIdentifiers, { type: "ISBN_10" }).identifier || '', - "isbn-13": _.find(book.industryIdentifiers, { type: "ISBN_13" }).identifier || '', + authorLast: _.join(book.authors ? _.lowerCase(_.head(_.reverse(_.split(book.authors[0], ' ')))), '') : '', + "isbn-10": _.find(book.industryIdentifiers, { type: "ISBN_10" }) + ? _.find(book.industryIdentifiers, { type: "ISBN_10" }).identifier + : '', + "isbn-13": _.find(book.industryIdentifiers, { type: "ISBN_13" }) + ? _.find(book.industryIdentifiers, { type: "ISBN_13" }).identifier + : '', format: '', genre: book.categories ? book.categories[0] : '', publisher: _.trim(book.publisher, '"'), @@ -143,7 +148,6 @@ function normalizeGoogleData(book) { notes: '', signed: '' }; - return normalized; } function appendToSheet(auth, book) { diff --git a/package.json b/package.json index cecc1d0..43e2eda 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,8 @@ "name": "library", "version": "1.0.0", "description": "Managing my personal library", - "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "start": "node ./index.js" }, "repository": { "type": "git",