Created
December 8, 2020 15:11
-
-
Save neno-tech/75787109380fde4e8269faa924d28379 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("xxx") | |
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(x=> x=="ขาด" || x=="ลา").length | |
var countLate = check.filter(x=> x=="สาย").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 นักเรียนทั้งหมด "+std+" คน \n มาเรียนทั้งหมด "+countCheck+" คน \n สาย "+countLate+" คน \n ไม่มาเรียน"+countNo+" คน ได้แก่ \n"+result | |
sendNotify(msg,token1) | |
// sendNotify(msg,token2) | |
// sendNotify(msg,token3) | |
} | |
var token1 ="xxx"//โทเคนครูที่ปรึกษา | |
//var token2 ="xxx"//โทเคนกลุ่มผู้ปกครอง | |
//var token3 ="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