Skip to content

Instantly share code, notes, and snippets.

@takahi5

takahi5/todoMail.js

Created Mar 17, 2019
Embed
What would you like to do?
var MAIL = 'yourmail@example.com';
/*
* タスクリストを取得
*/
function getTaskLists() {
var taskLists = Tasks.Tasklists.list().getItems();
if (!taskLists) {
return [];
}
return taskLists.map(function(taskList) {
return {
id: taskList.getId(),
name: taskList.getTitle()
};
});
}
/*
* 直近24Hに完了したタスクを取得
*/
function getLast24HoursTasks(taskListId) {
var now = new Date();
var yesterday = new Date()
yesterday.setDate(yesterday.getDate() - 1)
var i = Tasks.Tasks.list(taskListId)
var tasks = Tasks.Tasks.list(
taskListId,
{
showCompleted: true,
showDeleted: true,
showHidden: true,
completedMax: now.toISOString(),
completedMin: yesterday.toISOString()
}
).getItems();
if (!tasks) {
return [];
}
return tasks.map(function(task) {
return {
id: task.getId(),
title: task.getTitle(),
notes: task.getNotes(),
completed: new Date(Date.parse(task.getCompleted()))
};
}).filter(function(task) {
return task.title;
});
}
/*
* メールでレポート送信
*/
function sendReportEmail(tasks) {
// templateを読み込み
var templateIndex = HtmlService.createTemplateFromFile('index');
templateIndex.tasks = tasks;
html = templateIndex.evaluate().getContent();
// 送信
MailApp.sendEmail({
to: MAIL,
subject: tasks.length + '件のタスクを消化しました!',
htmlBody: html
});
}
function main() {
var taskLists = getTaskLists();
// 注) taskListは1つ前提
var tasks = getLast24HoursTasks(taskLists[0].id);
sendReportEmail(tasks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment