Skip to content

Instantly share code, notes, and snippets.

@hinklefoxmail hinklefoxmail/reminders.gs Secret
Created Sep 3, 2017

Embed
What would you like to do?
Automated Reminder System
function shareNewsletter() {
var folder = DriveApp.getFolderById('0B3QaE26f2r25OFZVMGxlM0syRG8')
var driveFile = DriveApp.getFileById('1mZEQniUTJurXWZeeZLI5zscI_FSNlFM11NHoH8FjeHo');
var date = new Date(Date.now()+777600000);
var formattedDate = Utilities.formatDate(date, "GMT+1", "MM/dd/yyyy");
var doc = driveFile.makeCopy(formattedDate + ' Newsletter Template', folder);
var url = doc.getUrl();
var editors = folder.getEditors();
Logger.log(editors);
for (var i = 0; i < editors.length; i++){
var message = 'Dear '+editors[i].getName()+',\n\nThe newsletter template for '+formattedDate+' is ready for editing:\n\n'+url+'\n\nThanks,\nJohn Hinkle';
MailApp.sendEmail(editors[i].getEmail(), 'Newletter template for '+formattedDate, message)
}
SpreadsheetApp.openById('1MUSToNCvPnkv_Ze6RjeKHub3rHh7DuvpRmsOWWWC19k').getSheetByName('newletterIDs').appendRow([doc.getId(),formattedDate,url])
}
function checkEdits(){
var idSheet = SpreadsheetApp.openById('1MUSToNCvPnkv_Ze6RjeKHub3rHh7DuvpRmsOWWWC19k').getSheetByName('newletterIDs')
var recentId = idSheet.getRange(idSheet.getLastRow(),1).getValue();
var url = idSheet.getRange(idSheet.getLastRow(),3).getValue();
Logger.log(recentId);
var doc = DocumentApp.openById(recentId).getBody();
var data = SpreadsheetApp.openById('1MUSToNCvPnkv_Ze6RjeKHub3rHh7DuvpRmsOWWWC19k').getSheetByName('sectionResponsibilties').getDataRange().getValues();
for (var i = 0; i < data.length; i++){
if (doc.findText(data[i][0])){
Logger.log(data[i][1])
var message = 'You still have not finished updating your section this weeks newsletter. Please do so soon:\n\n'+url+'\n\nThanks,\nJohn Hinkle';
var subject = 'Please Update the Newsletter';
} else {
var message = 'Thank-you for updating the newsletter. Please click below to check if your section is correct before I crete the newsletter\n\n'+url+'\n\nThanks,\nJohn Hinkle';
var subject = 'Newsletter Update';
}
MailApp.sendEmail(data[i][1], subject, message);
}
}
function checkEdits2(){
var idSheet = SpreadsheetApp.openById('1MUSToNCvPnkv_Ze6RjeKHub3rHh7DuvpRmsOWWWC19k').getSheetByName('newletterIDs')
var recentId = idSheet.getRange(idSheet.getLastRow(),1).getValue();
var url = idSheet.getRange(idSheet.getLastRow(),3).getValue();
Logger.log(recentId);
var doc = DocumentApp.openById(recentId).getBody();
var data = SpreadsheetApp.openById('1MUSToNCvPnkv_Ze6RjeKHub3rHh7DuvpRmsOWWWC19k').getSheetByName('sectionResponsibilties').getDataRange().getValues();
for (var i = 0; i < data.length; i++){
if (doc.findText(data[i][0])){
Logger.log(data[i][1])
var message = 'This is a remeinder to update your newsletter before tomorrow:\n\n'+url+'\n\nThanks,\nJohn Hinkle';
var subject = 'Newsletter Updates Due Tomorrow';
MailApp.sendEmail(data[i][1], subject, message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.