Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function emailCompletedTasks() {
- // emailCompletedTasks - Send daily summary of ToDoist completed tasks
- // Prereqs:
- // - Todoist account linked with IFTTT
- // - IFTTT recipe to capture every completed task in a Google sheet
- // - https://ifttt.com/applets/67297169d-put-all-your-completed-tasks-in-a-google-spreadsheet
- // Email address to send the data to
- var to = "myemailaddress@gmail.com";
- // Today's date in the same format as IFTTT ToDoist recipe uses. E.g. "December 12, 2017"
- var today = Utilities.formatDate(new Date(), "GMT-8", ("MMMMM d, yyyy"));
- // Subject line for the email with today's date appended
- var subject = "ToDone on " + today;
- // Open the sheet by name with the task data in it. By default, it will be "Sheet1"
- var s = SpreadsheetApp.getActive().getSheetByName('Sheet1');
- // Set up the regular expression to be todays date
- // - This will match the form of IFTTT's ToDoist date colume (e.g. "December 12, 2017")
- var regexp = new RegExp(today, "i");
- // Pull the first for columns of every row into an array
- var data = s.getRange('A:D').getValues();
- // Set up the default table format
- var TABLEFORMAT = 'cellspacing="2" cellpadding="2" dir="ltr" border="1" style="width:100%;table-layout:auto;font-size:10pt;font-family:arial,sans,sans-serif;border-collapse:collapse;border:1px solid #ccc;font-weight:normal;color:black;background-color:white;text-align:left;text-decoration:none;font-style:normal;'
- var body = '<table ' + TABLEFORMAT +' ">';
- body += '<tr>';
- body += '<th>' + "Task" + '</th><th>' + "Project" + '</th><th>' + "Tags" + '</th></tr>';
- // For every row in the spreadsheet, try to match today's date
- // - If matched, add Task, Project, and Tags cells to the table
- for( var row in data ) {
- if (regexp.test(data[row][2])) {
- body += '<td>' + data[row][0] + '</td>' + '<td>' + data[row][1] + '</td><td>' + data[row][3] + '</td>';
- body += '</tr>';
- }
- }
- body += '</table>';
- // Mail the table to the address specified
- MailApp.sendEmail(to, subject, '', {htmlBody: body});
- }
Add Comment
Please, Sign In to add comment