more updates

This commit is contained in:
David 2017-05-15 21:46:41 -04:00
parent c124ba7f4d
commit 1dd2c66884
2 changed files with 12 additions and 9 deletions

View File

@ -111,11 +111,12 @@ function insertRow(auth) {
field: 'isbn', field: 'isbn',
lang: 'en' lang: 'en'
}, function(error, results) { }, function(error, results) {
if ( ! error && results.length > 0) { if ( ! error && results.length > 0 ) {
console.log(results[0]);
var book = normalizeGoogleData(results[0]); var book = normalizeGoogleData(results[0]);
console.log(book); console.log(book);
appendToSheet(auth, _.values(book)); appendToSheet(auth, _.values(book));
} else if ( results.length == 0) { } else if ( results.length == 0 ) {
console.log("no book found"); console.log("no book found");
inputLoop(auth); inputLoop(auth);
} else { } else {
@ -126,12 +127,16 @@ function insertRow(auth) {
} }
function normalizeGoogleData(book) { function normalizeGoogleData(book) {
var normalized = { return {
title: book.subtitle ? book.title + ': ' + book.subtitle : book.title, title: book.subtitle ? book.title + ': ' + book.subtitle : book.title,
author: _.join(book.authors, ', '), author: _.join(book.authors, ', '),
authorLast: _.lowerCase(_.reverse(_.split(book.authors[0], ' '))[0]), authorLast: _.join(book.authors ? _.lowerCase(_.head(_.reverse(_.split(book.authors[0], ' ')))), '') : '',
"isbn-10": _.find(book.industryIdentifiers, { type: "ISBN_10" }).identifier || '', "isbn-10": _.find(book.industryIdentifiers, { type: "ISBN_10" })
"isbn-13": _.find(book.industryIdentifiers, { type: "ISBN_13" }).identifier || '', ? _.find(book.industryIdentifiers, { type: "ISBN_10" }).identifier
: '',
"isbn-13": _.find(book.industryIdentifiers, { type: "ISBN_13" })
? _.find(book.industryIdentifiers, { type: "ISBN_13" }).identifier
: '',
format: '', format: '',
genre: book.categories ? book.categories[0] : '', genre: book.categories ? book.categories[0] : '',
publisher: _.trim(book.publisher, '"'), publisher: _.trim(book.publisher, '"'),
@ -143,7 +148,6 @@ function normalizeGoogleData(book) {
notes: '', notes: '',
signed: '' signed: ''
}; };
return normalized;
} }
function appendToSheet(auth, book) { function appendToSheet(auth, book) {

View File

@ -2,9 +2,8 @@
"name": "library", "name": "library",
"version": "1.0.0", "version": "1.0.0",
"description": "Managing my personal library", "description": "Managing my personal library",
"main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "start": "node ./index.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",