Skip to content

Instantly share code, notes, and snippets.

@apg
Created August 28, 2014 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apg/fdad55a1af8604b41ce5 to your computer and use it in GitHub Desktop.
Save apg/fdad55a1af8604b41ce5 to your computer and use it in GitHub Desktop.
Google app script for hack and tell. Probably a dupe.
var PENDING_INVITE = '#fff2cc';
var INVITED = '#00ff00';
var CONFIRMED = '#ffff00';
var NOT_THIS_TIME = '#00ffff';
var NOT_THIS_TIME_SENT = '#4a86e8';
function markPerson(person, newtyp) {
var nameCell = person['range'].getCell(1, 1);
nameCell.setBackground(newtyp);
};
function findPeopleByType(typ) {
var ranges = []
, sheet = SpreadsheetApp.getActiveSheet()
, rows = sheet.getDataRange()
, numRows = rows.getNumRows()
for (var i = 1; i <= numRows - 1; i++) {
var range = sheet.getRange(i, 2);
if (range.getBackground() == typ) {
var range = sheet.getRange(i, 2, 1, 4)
, values = range.getValues();
ranges.push({
'range': range
, 'email': values[0][1]
, 'name': values[0][0]
, 'desc': values[0][3]
});
}
}
return ranges;
};
function getCommentary(range) {
var commentary = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("Commentary");
Logger.log(commentary.getColumn() + ': ' + commentary.getValue());
return commentary.getCell(range.getRow(), 1).getValue() || '<to be written>';
}
function generateWrapupEmail() {
var presenters = findPeopleByType(CONFIRMED)
, buffer = [];
buffer.push('# Round <insert number>: <insert name>');
buffer.push('Hello hackers,');
buffer.push('Thanks to <insert host>. <insert rest>');
buffer.push('## Projects Presented (in pseudo-random order)')
for (var i = 0; i < presenters.length; i++) {
var s = '### ' + presenters[i].name + '\n\n';
s += getCommentary(presenters[i].range);
s += '\n\n* []()';
buffer.push(s);
}
buffer.push('## Announcements and things to watch out for...');
buffer.push('Happy hacking,');
buffer.push('Andrew and James');
doOutput(buffer.join('\n\n'));
};
function formatYesEmail(name, desc) {
return "Hey " + name + ", \n\n" +
"You've been selected to present at Hack and Tell. Please let us know if you can still make it!\n\n" +
"In case you don't remember, this is what you told us:\n\n'''" +
desc +
"'''\n\n" +
"Happy Hacking,\n\n" +
"Andrew and James";
};
function formatNoEmail(name) {
return "Hey " + name + ", \n\n" +
"We couldn't confirm you for a presenter spot this time. Sorry! We have tried to RSVP you, however, if you weren't already.\n\n" +
"Happy Hacking,\n\n" +
"Andrew and James";
};
function invitePendingPresenters() {
var people = findPeopleByType(PENDING_INVITE);
for (var i = 0; i < people.length; i++) {
GmailApp.sendEmail(people[i]['email'], 'Presenting at Hack and Tell :)', formatYesEmail(people[i]['name'], people[i]['desc']), {
'from': 'apgwoz@gmail.com'
, 'cc': 'jdennis@gmail.com, apgwoz@gmail.com'
, 'name': 'Andrew "AppBot" Gwozdziewycz'
});
markPerson(people[i], INVITED);
Logger.log('Sending ok email to: ' + people[i]['email']);
}
};
function rejectPendingPresenters() {
var people = findPeopleByType(NOT_THIS_TIME);
for (var i = 0; i < people.length; i++) {
GmailApp.sendEmail(people[i]['email'], 'Presenting at Hack and Tell :(', formatNoEmail(people[i]['name']), {
'from': 'apgwoz@gmail.com'
, 'cc': 'jdennis@gmail.com, apgwoz@gmail.com'
, 'name': 'Andrew "AppBot" Gwozdziewycz'
});
markPerson(people[i], NOT_THIS_TIME_SENT);
Logger.log('Sending reject email to: ' + people[i]['email']);
}
};
function collectEmails(typ) {
var people = findPeopleByType(typ)
, emails = [];
for (var i = 0; i < people.length; i++) {
emails.push(people[i].email);
}
return emails;
};
function doOutput(thing) {
var cell = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("OutputField").getCell(1, 1);
cell.setValue(thing);
};
function outputConfirmedEmails() {
doOutput(collectEmails(CONFIRMED).join(', '));
};
function outputInvitedEmails() {
doOutput(collectEmails(INVITED).join(', '));
};
function outputRejectedEmails() {
doOutput(collectEmails(NOT_THIS_TIME_SENT).join(', '));
};
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [
{
name: "Invite Pending Presenters"
, functionName : "invitePendingPresenters"
},
{
name: "Reject Not-This-Time Presenters"
, functionName : "rejectPendingPresenters"
},
{
name: "Get Confirmed Emails"
, functionName: "outputConfirmedEmails"
},
{
name: "Get Invited Emails"
, functionName: "outputInvitedEmails"
},
{
name: "Get Rejected Emails"
, functionName: "outputRejectedEmails"
},
{
name: "Generate Wrapup"
, functionName: "generateWrapupEmail"
}
];
sheet.addMenu("Hack and Tell Tools", entries);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment