Skip to content

Instantly share code, notes, and snippets.

@yoonchulkoh
Created June 26, 2015 01:15
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 yoonchulkoh/03d14403eee46d0bd243 to your computer and use it in GitHub Desktop.
Save yoonchulkoh/03d14403eee46d0bd243 to your computer and use it in GitHub Desktop.
Google SpreadSheetからSlackに投げるスクリプト。GAS。refs: http://qiita.com/y_koh/items/81d8648914a893ec2d16
function getCrashCount() {
SpreadsheetApp.flush();
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var values = rows.getValues();
var threeDaysStartRow = 22;
var yesterdayStartRow = 36;
var count = 10;
var texts = [];
texts.push('```');
texts.push('# version');
texts = texts.concat(values[1][1]);
texts.push('');
texts.push('# within three days in the top ten');
texts.push('restaurant, count');
texts = texts.concat(getCrashTable(values, threeDaysStartRow, count));
texts.push('');
texts.push('# yesterday in the top ten');
texts.push('restaurant, count');
texts = texts.concat(getCrashTable(values, yesterdayStartRow, count));
texts.push('```');
var text = texts.join('\n');
Logger.log(text);
return text;
};
function getCrashTable(values, start, count) {
var texts = [];
for (var i = start-1; i < start-1+count; i++) {
var row = values[i];
Logger.log(row);
var rowText = row[0] + ', ' + row[1];
texts.push(rowText);
}
return texts;
}
function main() {
var slackToken = 'YOUR_SLACK_TOKEN';
var text = getCrashCount();
postSlack(slackToken, text);
}
function postSlack(token, text) {
var url = "https://hooks.slack.com/services/" + token;
var options = {
"method" : "post",
"payload" : JSON.stringify({ text: text })
};
UrlFetchApp.fetch(url, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment