Created
December 2, 2020 06:23
-
-
Save neno-tech/141e54d71a8f27bc866ac7c861aad294 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunction() { | |
var ss =SpreadsheetApp.getActiveSpreadsheet().getSheetByName('เช็คชื่อเข้าเรียน') | |
var names = ss.getRange(1, 2,1,ss.getLastColumn()).getValues()[0] | |
var check = ss.getRange(ss.getLastRow(), 2,1,ss.getLastColumn()).getDisplayValues()[0] | |
var date = Utilities.formatDate(new Date(), 'GMT+7', 'dd/MM/'); | |
var thaiyear = Number(Utilities.formatDate(new Date(), "GMT+7", "yyyy"))+543; | |
var index =1; | |
var count = check.filter(col=> col == "ขาด" || col == "ลา").length | |
var result = ""; | |
check.forEach((r,i)=>{ | |
if(r == "ขาด" || r == "ลา"){ | |
result += '\n'+(index++)+". "+names[i] +": "+ r } | |
}) | |
var msg="วันที่ "+date+thaiyear+"\n มีนักเรียนไม่มาเรียนจำนวน "+count+" คน ได้แก่"+ result | |
sendNotify(msg) | |
} | |
//ส่งไลน์แจ้งเตือน | |
function sendNotify(msg){ | |
let payloadJson = { | |
"message": msg | |
}; | |
let token = ["7zvnPWh6SROxMUbvl37MIo89B7FYmH2HEt6wpRIgh3h"]; //ใส่ token | |
let options = { | |
"method": "post", | |
"payload": payloadJson, | |
"headers": { | |
"Authorization": "Bearer " + token | |
} | |
}; | |
UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment