Created
February 10, 2013 10:44
-
-
Save adhipg/4749181 to your computer and use it in GitHub Desktop.
Returns a time formatted in H:mm if there is an active timer running in Toggl. I use this to add currently running timers to my `tmux-powerline`
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
#!/usr/bin/env node | |
var https = require('https'); | |
var options = { | |
hostname: 'www.toggl.com', | |
path: '/api/v6/time_entries.json', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
auth: "YOUR_API_TOKEN:api_token" | |
}; | |
var req = https.get(options, function(res) { | |
if( res.statusCode != '200' ) { | |
return ''; | |
} | |
res.setEncoding('utf8'); | |
var data = '', i; | |
res.on('data', function (chunk) { | |
data += chunk; | |
}); | |
res.on('end', function () { | |
var diff, minutes, hours; | |
try { | |
body = JSON.parse(data); | |
for(i = 0; i < body.data.length; i++) { | |
if( parseInt(body.data[i].duration, 10) < 0 ) { | |
diff = (Date.now() / 1000) + parseInt(body.data[i].duration, 10); | |
// diff += Date.now() / 1000; | |
minutes = Math.floor((diff % 3600) / 60); | |
minutes = (minutes < 10 ? '0' : '') + minutes; | |
hours = Math.floor(diff / 3600); | |
console.log(hours + ':' + minutes); | |
process.exit(0); | |
} | |
} | |
} | |
catch (ex) { | |
return ''; | |
} | |
}); | |
}); | |
req.on('error', function(e) { | |
return ''; | |
// console.log('problem with request: ' + e.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have an updated version for https://github.com/Lokaltog/powerline? — or does it needs to be updated at all?