iT邦幫忙

2025 iThome 鐵人賽

DAY 23
0

今天想到提醒功能,所以我決定讓他提醒我下一堂課要幾點去上

首先直接把學校的課表丟到notion中,因為這樣最省事,如果真的不會做這些,你可以點擊右下方的小人頭,然後跟他說你的要求,他就會自動幫你建立了
![https://ithelp.ithome.com.tw/upload/images/20251007/20177920gnXZ8H1Tyy.png]
建立好後就是n8n的回合了,一樣先開一個Schedule Trigger,讓他的觸發時間是每小時一次
https://ithelp.ithome.com.tw/upload/images/20251007/20177920UfSCoCfNor.png
接著去notion,到上次的開發或管理整合,點擊你的內部整合,在存取權限中新增你剛剛的資料庫
https://ithelp.ithome.com.tw/upload/images/20251007/20177920rN3bREzRHf.png
回到n8n,剛剛的schedule trigger後面+號查詢NOTION,選擇Get many database pages,就可以直接在from list那邊看到你剛剛的資料庫名稱了,把Simplify的部分取消勾選
https://ithelp.ithome.com.tw/upload/images/20251007/20177920k0SvIDNvwE.png
好了之後在後面+號加個code node,輸入

const today = ["週日","週一","週二","週三","週四","週五","週六"][new Date().getDay()];
const now = new Date(); // 確保是 Date

return items
  .filter(item => {
    const dayProp = item.json.properties['星期'].select;
    const startProp = item.json.properties['開始時間'].rich_text[0];
    if (!dayProp || !startProp) return false;

    const [hour, minute] = startProp.plain_text.split(':').map(Number);
    const startTime = new Date();
    startTime.setHours(hour, minute, 0, 0);

    // 兩邊都轉成 timestamp (number)
    const diffMinutes = (startTime.getTime() - now.getTime()) / (1000 * 60);

    return dayProp.name === today && diffMinutes > 0 && diffMinutes <= 60;
  })
  .map(item => {
    const startProp = item.json.properties['開始時間'].rich_text[0];
    const endProp = item.json.properties['結束時間'].rich_text[0];

    return {
      json: {
        title: item.json.properties['課程名稱'].title[0].text.content,
        url: item.json.url,
        start_time: startProp ? startProp.plain_text : null,
        end_time: endProp ? endProp.plain_text : null,
        day_of_week: item.json.properties['星期'].select.name
      }
    };
  });


這邊是讓他讀取今天日期及現在時間,只有在開始時間是在一個小時內的課才會接收到資料
最後send discode就完成了
https://ithelp.ithome.com.tw/upload/images/20251007/201779201kYufH6WFE.png
https://ithelp.ithome.com.tw/upload/images/20251007/20177920DW1s16Ev5A.png


上一篇
D22
下一篇
d24
系列文
這是一個一個一個 Python API 與 Gemini 整合、n8n入門指南28
  1. 24
    d24
  2. 25
    d25
  3. 26
    d26
  4. 27
    d27
  5. 28
    d28
完整目錄
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言