{
  "name": "IPTV_schedule",
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "http://10.18.200.198:8000/merge-to-excel",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"iptv_path\": \"{{ $('Extract IPTV Data').item.json.filename }}\",\n  \"infosite_path\": \"{{ $('Extract-infosite').item.json.file_path }}\",\n  \"output_filename\": \"{{ $('Code').item.json.today_ymd }}_{{ $('Code').item.json.tomorrow_ymd }}\"\n} ",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -272,
        752
      ],
      "id": "ed9ea760-2ba6-495a-9f4e-fac871e0b01f",
      "name": "Merge to Excel"
    },
    {
      "parameters": {
        "url": "=http://10.18.200.198:8000/download-excel",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "data_type",
              "value": "merge"
            },
            {
              "name": "filename",
              "value": "={{ $('Code').item.json.today_ymd }}_{{ $('Code').item.json.tomorrow_ymd }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -64,
        752
      ],
      "id": "74046653-6a56-4318-9b47-c5529dea8338",
      "name": "Get Execel"
    },
    {
      "parameters": {
        "fromEmail": "taiwan-demo@starific.net ",
        "toEmail": "robert.tseng@onelab.tw, ben.chen@onelab.tw,rdrd33@gmail.com,lientruong0508@gmail.com,sukyfeng87@gmail.com,rdrd33@gmail.com",
        "subject": "test",
        "emailFormat": "text",
        "text": "=Hi All \nThis is Up2 Data from  {{ $('Code').item.json.today_ymd }} to {{ $('Code').item.json.tomorrow_ymd }}",
        "options": {
          "attachments": "data"
        }
      },
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        112,
        752
      ],
      "id": "1184ba4e-8a96-444b-b589-963ed84dc1de",
      "name": "Send Result",
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://10.18.200.198:8000/check-leagues",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"start_time\": \"{{ $('Code').item.json.today_ymd }}\",\n  \"end_time\": \"{{ $('Code').item.json.tomorrow_ymd }}\",\n  \"filename\": \"{{ $('Code').item.json.today_ymd }}_{{ $('Code').item.json.tomorrow_ymd }}\",\n  \"league_groups\": [\n    \"Soccerway\",\n    \"IMG\",\n    \"Virtual\",\n    \"RB Upload\",\n    \"RTS Upload\",\n    \"BG Upload\",\n    \"BETRADAR Upload\"\n  ]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -112,
        528
      ],
      "id": "f85b8e27-f6bd-42f0-9f4a-69bc75d11721",
      "name": "League_Name"
    },
    {
      "parameters": {
        "amount": "={{ $('Extract League').item.json.batches }}",
        "unit": "minutes"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        368,
        528
      ],
      "id": "d71cd753-8bc7-42e4-aae2-a62f4269fbfc",
      "name": "Wait"
    },
    {
      "parameters": {
        "jsCode": "const raw = String($input.first().json.leagues);\n\nlet items = raw.split(\",\")// \n  .map(item => `\"${item}\"`);                   // \u52a0\u4e0a\u5f15\u865f\nconst count = items.length;\nconst batches = Math.ceil(count / 50); \nreturn {\n  result: `[${items.join(\", \")}]`,\n  batches: batches*4\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        48,
        528
      ],
      "id": "f4e09f14-9ee4-42ce-be21-7d0e75a798ee",
      "name": "Extract League"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://10.18.200.198:8000/download-infosite",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"start_time\": \"{{ $('Code').item.json.today_ymd }}\",\n  \"end_time\": \"{{ $('Code').item.json.tomorrow_ymd }}\",\n  \"filename\": \"{{ $('Code').item.json.today_ymd }}_{{ $('Code').item.json.tomorrow_ymd }}\",\n  \"leagues\": {{ $json.result }},\n  \"league_groups\": [\n    \"Soccerway\",\n    \"IMG\",\n    \"Virtual\",\n    \"RB Upload\",\n    \"RTS Upload\",\n    \"BG Upload\",\n    \"BETRADAR Upload\"\n  ],\n  \"sports\": [\n    \"Soccer\"\n  ],\n  \"save_features\": [],\n  \"batch_size\": 50\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        224,
        528
      ],
      "id": "8dc92600-ef4f-46a2-bcd2-677657a5e018",
      "name": "Extract-infosite"
    },
    {
      "parameters": {
        "content": "## Extract IPTV and Infosite Data",
        "height": 240,
        "width": 832
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -336,
        432
      ],
      "id": "3e375e22-a7df-4d9b-b688-43f5a87b4bfc",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Merge to formula and Send Email ",
        "height": 224,
        "width": 832,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -336,
        672
      ],
      "id": "651ed9c3-7293-41ae-8f54-e6f286d11e0d",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## Execute next fifth day\n",
        "height": 192,
        "width": 832,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -336,
        240
      ],
      "id": "50a4e20a-97e9-4488-a71a-de580b8073a4",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://10.18.200.198:8000/download-iptv",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "start_date",
              "value": "={{ $json.today_dmy }}"
            },
            {
              "name": "end_date",
              "value": "={{ $json.tomorrow_dmy }}"
            },
            {
              "name": "=filename",
              "value": "={{ $json.today_ymd }}_{{ $json.tomorrow_ymd }}.csv"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -272,
        528
      ],
      "id": "58bb185d-9a85-48bf-9438-f01778f1c77b",
      "name": "Extract IPTV Data"
    },
    {
      "parameters": {
        "jsCode": "const today = new Date();\n\n// \u2795 8 \u5c0f\u6642\nconst todayPlus8 = new Date(today.getTime() + 8 * 60 * 60 * 1000);\ntodayPlus8.setDate(todayPlus8.getDate() + $input.first().json.day); \n// \u660e\u5929\nconst tomorrow = new Date();\ntomorrow.setDate(todayPlus8.getDate() + 1);\n\n// \u683c\u5f0f\u5316 yyyy-mm-dd\nfunction formatYYYYMMDD(date) {\n  return date.toISOString().split(\"T\")[0];\n}\n\n// \u683c\u5f0f\u5316 dd/mm/yyyy\nfunction formatDDMMYYYY(date) {\n  const dd = String(date.getDate()).padStart(2, '0');\n  const mm = String(date.getMonth() + 1).padStart(2, '0');\n  const yyyy = date.getFullYear();\n  return `${dd}/${mm}/${yyyy}`;\n}\n\n// \u56db\u500b\u7d50\u679c\nconst result = {\n  today_ymd: formatYYYYMMDD(todayPlus8),       // 2025-09-17 (UTC+8 \u5f8c\u7684\u65e5\u671f)\n  tomorrow_ymd: formatYYYYMMDD(tomorrow),      // 2025-09-18\n  today_dmy: formatDDMMYYYY(todayPlus8),       // 17/09/2025\n  tomorrow_dmy: formatDDMMYYYY(tomorrow)       // 18/09/2025\n};\n\n// \u56de\u50b3\u7d66 n8n\nreturn [{ json: result }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -64,
        288
      ],
      "id": "430fbe35-93da-479c-94cf-d4e724fe5d19",
      "name": "Code"
    },
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "day",
              "type": "number"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -288,
        288
      ],
      "id": "f4b4a6f9-4d1c-4127-b6d6-32a37c6311a1",
      "name": "When Executed by Another Workflow"
    }
  ],
  "connections": {
    "Merge to Excel": {
      "main": [
        [
          {
            "node": "Get Execel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Execel": {
      "main": [
        [
          {
            "node": "Send Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "League_Name": {
      "main": [
        [
          {
            "node": "Extract League",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract League": {
      "main": [
        [
          {
            "node": "Extract-infosite",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Merge to Excel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract-infosite": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract IPTV Data": {
      "main": [
        [
          {
            "node": "League_Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Extract IPTV Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all",
    "saveExecutionProgress": true,
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner",
    "errorWorkflow": "G25m5HDkXmJY3hma",
    "timeSavedPerExecution": 0
  },
  "versionId": "d03b351e-dd78-42c1-a089-441a45f6bd3f",
  "id": "G25m5HDkXmJY3hma",
  "tags": []
}