Last active
December 28, 2020 21:42
-
-
Save neno-tech/e90629180e4273772c4d529d0c07d97c 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('xxxxx') | |
var names = ss.getRange(1, 2, 1, ss.getLastColumn()).getValues()[0] | |
var check = ss.getRange(ss.getLastRow(), 2, 1, ss.getLastColumn()).getValues()[0] | |
var date = Utilities.formatDate(new Date(), 'GMT+7', 'dd/MM/')//วันที่ | |
var year = 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+year+"\n มีนักเรียนไม่มาเรียนจำนวน "+count+" คน ได้แก่"+result | |
sendNotify(msg) | |
} | |
//ส่งไลน์แจ้งเตือน | |
function sendNotify(msg){ | |
let payloadJson = { | |
"message": msg | |
}; | |
let token = ["xxx"]; //ใส่ 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