#!/usr/local/bin/node

var db = require("../lib/db.js")
var util = require("../lib/util.js")

var counter = 0
var totalChanged = 0



db.allBibs(function(bib,cursor,mongoConnection){

	process.stdout.clearLine()
	process.stdout.cursorTo(0)
	process.stdout.write( counter + " | " + totalChanged)

	counter++

	var hasChecked = (bib['sc:classifyCheck']) ? true : false
	


	if (!hasChecked){


			//build out the data we would use in classify
			var data = {
				_id: bib._id,
				oclc : [],
				isbn : [],
				issn : [],
				title : false,
				author : false
			}

			if (bib['sc:oclc']){
				for (var x in bib['sc:oclc']){
					data.oclc.push(bib['sc:oclc'][x])
				}
			}

			if (bib['lc:oclc']){
				for (var x in bib['lc:oclc']){
					data.oclc.push(bib['lc:oclc'][x])
				}
			}
			if (bib['sc:isbn']){
				for (var x in bib['sc:isbn']){
					data.isbn.push(bib['sc:isbn'][x])
				}
			}
			if (bib['sc:issn']){
				for (var x in bib['sc:issn']){
					data.issn.push(bib['sc:issn'][x])
				}
			}

			if (bib['author']){
				data.author = bib['author']
			}
			if (bib['title']){
				data.title = bib['title']
			}

			

			db.insertAPIClassifyRecord(data,function(err,results){

				cursor.resume()

				//console.log(data)
				//if (results) console.log(results.result)

			})

			return true



			

	}
	
	cursor.resume()





})


@@ -289,16 +289,107 @@
 anged)%0A%0A
+%0A%09if (!bib)%7B%0A%09%09console.log(%22Complete:%22, counter + %22 %7C %22 + totalChanged)%0A%09%09return true;%0A%09%7D%0A%0A
 %09counter
@@ -1268,16 +1268,36 @@
 ults)%7B%0A%0A
+%09%09%09%09totalChanged++%0A%0A
 %09%09%09%09curs

classify api data job