Created
December 7, 2020 06:31
-
-
Save neno-tech/c97bb27926b8ad3b82170194d5137d38 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()).getValues()[0] | |
var std = names.length-1 | |
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 countNo = check.filter(col=> col =="ขาด" || col == "ลา").length //นับจำนวน ขาดและลา | |
var countLate = check.filter(col=> col == "สาย").length //นับจำนวน มาสาย | |
var countCheck = std-countNo | |
var result = "" | |
check.forEach((row,i)=>{ | |
if(row =="สาย" || row == "ลา" || row == "ขาด"){ | |
result+= "\n"+(index++)+". เลขที่ "+names[i]+": "+row | |
} | |
}) | |
var msg = "📌ประจำวันที่ "+date+year+"\n 📣นักเรียน ม.2/3 ทั้งหมด"+ std+" คน \n ✅️มาเรียนทั้งหมด "+countCheck +" คน \n ⏰มาสาย "+countLate+" คน \n ❌ไม่มาเรียน "+countNo+" คน \n 📊สรุปรายชื่อนักเรียน(มาสาย,ขาด,ลา) มีดังนี้"+result | |
sendNotify(msg,token1) | |
// sendNotify(msg,token2) | |
} | |
let token1 ="xxx"; | |
// let token2 ="xxx"; | |
//ส่งไลน์แจ้งเตือน | |
function sendNotify(msg,token){ | |
let payloadJson = { | |
"message": msg | |
}; | |
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