Created
February 3, 2013 20:41
-
-
Save jacobandresen/4703578 to your computer and use it in GitHub Desktop.
timelog
This file contains hidden or 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 TimeLog = function (options) { | |
function appendToFile (projectId) { | |
var now = new Date(); | |
var line = now.getHours() +":" + now.getMinutes() + " " + projectId +"\r\n"; | |
fs.appendFile("data.txt", line, function (err) { | |
if (err) { | |
console.log(err); | |
} | |
}); | |
} | |
function listProjectsFromDisk (callback) { | |
fs.readFile("projects.txt", function (err, data) { | |
if (err) throw err; | |
console.log(data.toString()); | |
if (callback) { | |
callback(); | |
} | |
}); | |
} | |
return ({ | |
list: function (callback) { | |
listProjectsFromDisk(callback); | |
}, | |
start: function (projectId) { | |
appendToFile (projectId); | |
}, | |
stop: function () { | |
appendToFile (-1); | |
} | |
}); | |
}; | |
var t = new TimeLog(); | |
t.list( function () { | |
var prompt = require('prompt'); | |
prompt.get(['id'], function (err, result) { | |
t.start(result.id); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment