Skip to content

Instantly share code, notes, and snippets.

@ejain

ejain/logsit.js Secret

Created January 6, 2015 00:37
Show Gist options
  • Save ejain/efb01fe456e737425e75 to your computer and use it in GitHub Desktop.
Save ejain/efb01fe456e737425e75 to your computer and use it in GitHub Desktop.
var csv = require("ya-csv");
var moment = require("moment-timezone");
// set up the csv reader
var reader = csv.createCsvStreamReader(process.openStdin(), {});
// our data will be added to this list
var events = [];
// handle each row in the spreadsheet
reader.addListener("data", function(row) {
if (row.length > 5 && Number(row[0]) > 0) { // ignore header and empty lines
// concatenate the date and time, and set a time zone
var timestamp = moment.tz(
row[2] + " " + row[3] + " " + row[4],
"MMMM D, YYYY HH:mm",
"America/Los_Angeles"
);
// add a default tag, plus an optional tag
var tags = [ "Habit" ];
if (row[1]) {
tags.push(row[1]);
}
var event = {
"timestamp" : timestamp.format("YYYY-MM-DDTHH:mm:ss.SSSSZ"), // ISO8601
"tag" : tags
};
// add a note, if present
if (row[5]) {
event["note"] = row[5];
}
events.push(event);
}
});
// print our data to the console at the end
reader.addListener("end", function(row) {
console.log(JSON.stringify({ "events" : events }, null, " "));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment