Skip to content

Instantly share code, notes, and snippets.

@yuumi3
Last active December 25, 2018 05:29
Show Gist options
  • Save yuumi3/83cf16f56a336e6bd251679418deb3c9 to your computer and use it in GitHub Desktop.
Save yuumi3/83cf16f56a336e6bd251679418deb3c9 to your computer and use it in GitHub Desktop.
addTodoTask
const TODO_PATH = '/Notes/TODO.md'
const fetch = require('isomorphic-fetch')
const Dropbox = require('dropbox').Dropbox
const dbx = new Dropbox({ accessToken: process.env["TOKEN"], fetch: fetch })
const mmdd = (d) => `${d.getMonth() + 1}/${d.getDate()}`
exports.handler = async (event, context, callback) => {
try {
const task = event.task ? event.task : "TEST"
const meta = await dbx.filesDownload({path: TODO_PATH})
const todo = meta.fileBinary.toString('utf-8').trimRight()
const todoNew = todo.concat(`\n- [ ] ${task} ${mmdd(new Date())}\n`)
await dbx.filesUpload({path: TODO_PATH, contents: todoNew, mode: 'overwrite'})
}
catch (e) {
console.error(e)
}
}
if (process.platform == "darwin") {
exports.handler({task: "Mac バックアップ"}, {}, () => {console.log("end")})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment