Last active
December 25, 2018 05:29
-
-
Save yuumi3/83cf16f56a336e6bd251679418deb3c9 to your computer and use it in GitHub Desktop.
addTodoTask
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
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