Table of Contents
はじめに
退職まであと何日か?名言を添えて教えてくれるスクリプトです。
あとはメイン関数を定期的に実行させるだけ!
内容
// メイン関数function Countdown() { // カウントダウンデータを取得 const json = fetchData(); const parsedJson = JSON.parse(json);
// 今日の日付を取得 let today = new Date(); today = Utilities.formatDate(today, "JST", "yyyy-MM-dd");
// 今日の日付に合致するデータを取得 const matchingQuote = parsedJson.filter((entry) => entry.date === today);
if (matchingQuote) { const message = `退職まであと${matchingQuote[0].countdown}日!『${matchingQuote[0].famous_quote}』by ${matchingQuote[0].author}`;
// Slackに通知 // https://barorin-to.com/posts/gas-to-slack-function/ の記事を参照 sendSlackMessage( "https://hooks.slack.com/services/hogehoge", "退職まであとn日Bot", ":partying_face:", message, ); }}
// カウントダウンデータfunction fetchData() { // 実際はエクセルで作ってChatGPTにJSON化してもらいました。 const data = [ { date: "2024-02-28", countdown: "100", famous_quote: "You will be singled out for promotion in your work.", author: "cow", }, // あとは好きなだけカウントダウンする ];
return JSON.stringify(data);}