Last active
August 29, 2015 13:57
-
-
Save issa-tseng/9735718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var soda = require('soda-js'); | |
var moment = require('moment'); | |
var update = /* some configuration we load in from a local JSON file */; | |
// read in our csv | |
fs.readFile(update.file, function(error, data) | |
{ | |
if (error) { console.error(error); return; } | |
// split apart our csv into lines | |
var lines = data.toString().split('\n'); | |
var parsedData = []; | |
// iterate through each line | |
for (var j = 0; j < lines.length; j++) | |
{ | |
// parse each line and warn if we run into anything unexpected | |
var fields = csvToArray(lines[j]); | |
if (fields.length === 0) { console.warn('Warning: skipping empty row in file ' + update.file); continue; } | |
if (fields.length !== update.columns.length) { console.error('Expected ' + update.columns.length + ' columns for ' + update.file + ' but got ' + fields.length + '!'); return; } | |
// save off that line | |
parsedData.push(fields); | |
} | |
// parsedData now contains our data | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment