37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
const Beeminder = require('./Beeminder.js')
|
|
const Marvin = require('./Marvin.js')
|
|
const fs = require('fs')
|
|
const BEEMINDER_TOKEN = fs.readFileSync("./beeminder-token", 'utf8').trim()
|
|
const {DateTime, Interval, Duration} = require('luxon')
|
|
|
|
function sleep(n) {
|
|
return new Promise((resolve, reject) => {
|
|
setTimeout(resolve, n)
|
|
})
|
|
}
|
|
|
|
if (require.main === module) {
|
|
(async function() {
|
|
const m = new Marvin()
|
|
const d = DateTime.local()
|
|
const today = Interval.fromDateTimes(d.startOf('day'), d.endOf('day'))
|
|
const tasks = await (m.root.category('Tweag').then(tweag => tweag.tasksOverlapping(today)))
|
|
const value = Duration.sum(tasks.map(task => task.timeSpentOn(today))).as('hours')
|
|
|
|
const b = new Beeminder(BEEMINDER_TOKEN)
|
|
const goal = b.user("me").goal("loonslaven")
|
|
const daystamp = d.toFormat('yyyyMMdd')
|
|
const post_data = {
|
|
daystamp,
|
|
value,
|
|
requestid: daystamp,
|
|
comment: "from marvin"
|
|
}
|
|
console.log(post_data)
|
|
console.log(await goal.create_datapoint(post_data))
|
|
await sleep(2000)
|
|
console.log((await goal.info()).safesum)
|
|
})()
|
|
|
|
}
|