{
 "name": "[노드 한 장] Loop Over Items · 12개 도시 날씨, 3개씩",
 "nodes": [
  {
   "id": "b1",
   "name": "Run manually",
   "type": "n8n-nodes-base.manualTrigger",
   "typeVersion": 1,
   "position": [
    0,
    200
   ],
   "parameters": {}
  },
  {
   "id": "b2",
   "name": "12 cities",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    220,
    200
   ],
   "parameters": {
    "jsCode": "const cities = [\n  ['Seoul',37.57,126.98],['Tokyo',35.68,139.69],['Beijing',39.90,116.41],\n  ['Singapore',1.35,103.82],['Mumbai',19.08,72.88],['Dubai',25.20,55.27],\n  ['London',51.51,-0.13],['Paris',48.86,2.35],['Berlin',52.52,13.40],\n  ['New York',40.71,-74.01],['Sao Paulo',-23.55,-46.63],['Sydney',-33.87,151.21],\n];\nreturn cities.map(([city, lat, lon]) => ({ json: { city, lat, lon } }));"
   }
  },
  {
   "id": "b3",
   "name": "Loop Over Items",
   "type": "n8n-nodes-base.splitInBatches",
   "typeVersion": 3,
   "position": [
    440,
    200
   ],
   "parameters": {
    "batchSize": 3,
    "options": {}
   }
  },
  {
   "id": "b4",
   "name": "Get weather",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    680,
    300
   ],
   "parameters": {
    "url": "=https://api.open-meteo.com/v1/forecast?latitude={{ $json.lat }}&longitude={{ $json.lon }}&current=temperature_2m",
    "options": {}
   }
  },
  {
   "id": "b5",
   "name": "Keep city + temp",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    900,
    300
   ],
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "c1",
       "name": "city",
       "type": "string",
       "value": "={{ $('Loop Over Items').item.json.city }}"
      },
      {
       "id": "c2",
       "name": "temp_c",
       "type": "number",
       "value": "={{ $json.current.temperature_2m }}"
      },
      {
       "id": "c3",
       "name": "checked_at",
       "type": "string",
       "value": "={{ $now.setZone('Asia/Seoul').toFormat('HH:mm:ss') }}"
      }
     ]
    },
    "options": {}
   }
  },
  {
   "id": "b6",
   "name": "Wait 1s",
   "type": "n8n-nodes-base.wait",
   "typeVersion": 1.1,
   "position": [
    1120,
    300
   ],
   "parameters": {
    "amount": 1,
    "unit": "seconds"
   }
  },
  {
   "id": "b7",
   "name": "All done",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    680,
    60
   ],
   "parameters": {
    "jsCode": "const rows = $input.all().map(i => i.json);\nconst hot = rows.reduce((a, b) => (b.temp_c > a.temp_c ? b : a));\nconst cold = rows.reduce((a, b) => (b.temp_c < a.temp_c ? b : a));\nreturn [{ json: { cities: rows.length, hottest: `${hot.city} ${hot.temp_c}°C`, coldest: `${cold.city} ${cold.temp_c}°C` } }];"
   }
  }
 ],
 "connections": {
  "Run manually": {
   "main": [
    [
     {
      "node": "12 cities",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "12 cities": {
   "main": [
    [
     {
      "node": "Loop Over Items",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Loop Over Items": {
   "main": [
    [
     {
      "node": "All done",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Get weather",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Get weather": {
   "main": [
    [
     {
      "node": "Keep city + temp",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Keep city + temp": {
   "main": [
    [
     {
      "node": "Wait 1s",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Wait 1s": {
   "main": [
    [
     {
      "node": "Loop Over Items",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "timezone": "Asia/Seoul",
  "executionOrder": "v1"
 },
 "meta": {
  "templateCredsSetupCompleted": false,
  "source": "datapopcorn.ai/workflow/nodes"
 }
}