-
-
Save dshack/5bf04f8e4c196a07c99e to your computer and use it in GitHub Desktop.
Logsit importer for Zenobase
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 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