製ä½ã®èæ¯
çå¨ãæ¯ããç±ä¸çãæ»è ãåºã¦ãã¾ãã
ãããªä¸ãç±ä¸çè¦æã¢ã©ã¼ãã¨ãããã®ããããã¨ããåãã®æ¹ãå¤ãã§ãããã
ããã¯WBGTã33以ä¸ã¨ãªããã¨ãäºæ³ãããå ´åã«ãå¤ãã¯é½éåºçæ¯ã«çºè¡¨ããããã®ã§ãã
詳ããã¯ç°å¢çã®ãµã¤ãã«èª¬æãè²ãã¾ãã
ãããªä¸ãç±ä¸çè¦æã¢ã©ã¼ããåºã¦ããããæé å çãæ¥å ±ã«æ¸ãã¨ããéç¨ãã¹ã¿ã¼ããããã§ããããã ã§ãããå¿ããæé å çã®æãç ©ããã®ãæ°ãå¼ããã®ã§ãGASã§éç¥botãä½æãã¾ããã
ç°å¢çã®ãµã¤ãã¯GASããã¢ã¯ã»ã¹ã§ããªã
ç°å¢çç±ä¸çäºé²æ
å ±ãµã¤ãã§ã¯WBGTã®äºæ¸¬å¤ãCSVã§åããã¨ãã§ãã¾ãã
ã§ãããããã®CSVãGASã§ãã§ãã¯ãã¦ã33度以ä¸ã«ãªã£ã¦ãããã§å¤å®ãããã¨æã£ãã®ã§ãã
ã¨ãããããªããã¯ç¥ãã¾ãããããã®ãã¼ã¿ãGASããèªã¿è¾¼ããã¨ãã§ãã¾ããããã¡ã¤ã³ã¾ããã¨ãã¡ã§ããã
æ°è±¡åºã«JSONããã£ã
ãªããæ°è±¡åºã®ãµã¤ãã使ãããç¡ãã¨ãããã¨ã§ãæ°è±¡åºã®ãµã¤ãã
ã½ã¼ã¹è¦ãã¨ãã¤ãããã®ä½ãã¨ããããå ¨é¨JavaScriptã§ãããããã®ã¾ã¾èªã¿è¾¼ãã§ãä»æ¹ãªãæ§åã
ãããªä¸ãjsonãã¡ã¤ã«ãçºè¦ã
https://www.jma.go.jp/bosai/information/data/information.json
ãããè¦ã¦ããã¨ãç±ä¸çè¦æã¢ã©ã¼ãã«ã¤ãã¦ããã¡ãã¨å ¥ã£ã¦ãããã¨ã確èªã
次ã®ãããªæ¡ä»¶ã«ãªãã¾ãã
- ç±ä¸çè¦æã¢ã©ã¼ãã¯åæ¥ã®17æã¨å½æ¥ã®5æã«çºè¡¨ãããã
- 17æã«çºè¡¨ãããå ´åã¯ã¢ã©ã¼ãããã£ã³ã»ã«ã®å ´åã§ã5æã®çºè¡¨ã¯ãããã¬ã¢ã±ã¼ã¹ã ããã¨åæã«æ¨æ¸¬
- ãªã®ã§ã5æã®çºè¡¨ãè¦ãã°ãããreportDatetimeãã2023-08-31T05:00:00+09:00ãã®å½¢ã«ãªãã
- JSONã® controlTitle ããç±ä¸çè¦æã¢ã©ã¼ãã
- åãã headTitle ããå°åå+ç±ä¸çè¦æã¢ã©ã¼ããï¼ä¾ï¼å¼ççç±ä¸çè¦æã¢ã©ã¼ãï¼
ã¨è¨ã訳ã§ãããã§ã©ãã«ããªãããã§ãã
å¦çã®æµã
- 5æãã6æã®éã§GASèµ·å
- æ°è±¡åºã®JSONåå¾
- æ¡ä»¶ã«åããã®ããããæ¢ã
- ãã£ããWebhookã§Google Chatã«æãã
GASèµ·åã¨ãWebhookã®èª¬æã¯ååéãGASã§èª¬æããã®ã§çç¥ãã¾ãã
å®éã®ã½ã¼ã¹
function myFunction() { //åæè¨å® let area = "å¼çç"; let WebhookUrl = "https://chat.googleapis.com/v1/spaces/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; var today = new Date (); let alart = 0; //èªã¿è¾¼ã¾ãããã¡ã¤ã« let url = "https://www.jma.go.jp/bosai/information/data/information.json"; var response = UrlFetchApp.fetch(url).getContentText(); let json = JSON.parse(response); let jsonNum = json.length; //é åã®æ°ãã«ã¦ã³ããã //å½æ¥ã®æ5æã®æ å ±ã¨ãªãããã«æååãä½ã var d = new Date(); let y = d.getFullYear(); let m = d.getMonth() + 1; if(m<10){m = "0"+m;} //1-9æã¯01-09æã¨ãã let d2 = d.getDate(); if(d2<10){d2 = "0"+d2} //1-9æ¥ã¯01-09æ¥ã¨ãã let todaydate = y+"-"+m+"-"+d2+"T05:00:00+09:00"; //2023-08-30T05:00:00+09:00 ã®å½¢ //é åãç §åãã¦å½æ¥ã«çºåºãããç±ä¸çè¦æã¢ã©ã¼ããæ¢ã for(i=0;i<jsonNum;i++){ if(json[i]["controlTitle"]=="ç±ä¸çè¦æã¢ã©ã¼ã" && json[i]["headTitle"] == area+"ç±ä¸çè¦æã¢ã©ã¼ã" && json[i]["reportDatetime"] == todaydate){ alart = 1; //ãã©ã°ãç«ã¦ã }; } if (isWorkday (today) == true && alart == 1) { //以ä¸å¹³æ¥ã§ã¢ã©ã¼ããONã®æã«åä½ //Googleãã£ããã§æ稿ãããããã¡ãã»ã¼ã¸ãå®ç¾©ãã let message = { 'text' : "ã"+area+"ãæ¬æ¥ãç±ä¸çè¦æã¢ã©ã¼ããçºè¡¨ããã¦ãã¾ãã念ã®ããææ°æ å ±ãã確èªãã ããã"+"\n"+"https://www.wbgt.env.go.jp/alert.php" }; let options = { 'payload' : JSON.stringify(message), 'myamethod' : 'POST', 'contentType' : 'application/json' }; //Webhookã®URL対ãHTTP POSTãå®è¡ãã let response = UrlFetchApp.fetch(WebhookUrl,options); } } //ä»¥ä¸ https://dev.classmethod.jp/articles/202001-workday-only-gas/ ãã function isWorkday (targetDate) { // targetDate ã®ææ¥ã確èªãåæ¥ã¯ä¼ã (false) var rest_or_work = ["REST","mon","tue","wed","thu","fri","REST"]; // æ¥ãå if ( rest_or_work [targetDate.getDay ()] == "REST" ) { return false; }; // å ¨ã¦å½ã¦ã¯ã¾ããªããã°å¶æ¥æ¥ (True) return true; }ã¨
ã¨è¨ã訳ã§ãåä½ç¢ºèªã
ãããããOKOKã
ã¨è¨ã訳ã§ãä¸æéãããã ãã§ã¿ããªã楽ã«ãªããã大ããªäºæ ãé²ããã®ã§ããã°å¤§æè¿ã§ãã
çãããæ¯éã試ããï¼