RECIPE 008
날씨 API 연동 → 우천 시 자동 알림
- ▸Reddit API를 HTTP Request로 호출해 게시물을 수집할 수 있다
- ▸키워드 필터링 + 점수(upvote) 기준으로 양질의 글만 추릴 수 있다
- ▸Slack 또는 Sheets로 결과를 자동 저장할 수 있다
✅사전 준비
- □Reddit 계정 생성 후 앱 등록 (https://www.reddit.com/prefs/apps)
- □Client ID, Client Secret 발급
- □n8n에 HTTP Request용 Reddit OAuth2 Credentials 등록
- □모니터링할 서브레딧 이름 목록 준비 (예: r/n8n, r/automation)
Reddit API — 인증 토큰 요청
URL: https://www.reddit.com/api/v1/access_token
Method: POST
Auth: Basic (Client ID / Client Secret)
Body(Form):
grant_type: client_credentials서브레딧 최신 게시물 수집
URL: https://oauth.reddit.com/r/n8n/new
Method: GET
Headers:
Authorization: Bearer {{ $json.access_token }}
User-Agent: n8n-monitor/1.0
Query Parameters:
limit: 25점수 + 키워드 필터 — IF 노드
upvote 10 이상:
{{ $json.data.score >= 10 }}
키워드 포함:
{{ ["automation","workflow","n8n"].some(k =>
$json.data.title.toLowerCase().includes(k)
) }}💡 TIPReddit API는 인증 없이 /r/서브레딧/new.json 으로도 기본 데이터를 가져올 수 있어요. 간단히 테스트할 땐 인증 없이 먼저 시도해보세요.
⚡
워크플로우 JSON
아래 JSON을 복사해 n8n에 바로 임포트하세요
📥 n8n 임포트 방법
n8n 화면 우측 상단 메뉴 (⋮) → Import from JSON → 아래 JSON 전체 복사 후 붙여넣기 → Import 클릭
n8n 화면 우측 상단 메뉴 (⋮) → Import from JSON → 아래 JSON 전체 복사 후 붙여넣기 → Import 클릭
{
"name": "recipe008_weather_rain_alert",
"nodes": [
{
"parameters": {
"rule": {
"interval": [
{
"field": "hours",
"triggerAtHour": 6,
"triggerAtMinute": 0
}
]
}
},
"id": "schedule-008-01",
"name": "매일 오전 6시 트리거",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.2,
"position": [
200,
400
]
},
{
"parameters": {
"method": "GET",
"url": "https://api.openweathermap.org/data/2.5/weather",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "q",
"value": "Seoul,KR"
},
{
"name": "appid",
"value": "={{ $env.OPENWEATHER_API_KEY }}"
},
{
"name": "units",
"value": "metric"
},
{
"name": "lang",
"value": "kr"
}
]
},
"options": {}
},
"id": "http-008-02",
"name": "OpenWeatherMap 날씨 요청",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
420,
400
]
},
{
"parameters": {
"jsCode": "const weatherId = $json.weather?.[0]?.id ?? 800;\nconst weatherDesc = $json.weather?.[0]?.description ?? '';\nconst temp = $json.main?.temp ?? 0;\nconst tempMax = $json.main?.temp_max ?? 0;\nconst isRainy = weatherId >= 200 && weatherId < 700;\nreturn [{\n json: {\n isRainy,\n weatherId,\n weatherDesc,\n temp: Math.round(temp),\n tempMax: Math.round(tempMax)\n }\n}];"
},
"id": "code-008-03",
"name": "날씨 데이터 분석",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
400
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": false,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "cond-rainy",
"leftValue": "={{ $json.isRainy }}",
"rightValue": true,
"operator": {
"type": "boolean",
"operation": "equals"
}
}
],
"combinator": "and"
}
},
"id": "if-008-04",
"name": "비 또는 눈 예보 확인",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
860,
400
]
},
{
"parameters": {
"resource": "message",
"operation": "post",
"channel": "#weather-alerts",
"text": "={{ '🌧️ *오늘 비 예보가 있어요!*\\n\\n날씨 상태: ' + $json.weatherDesc + '\\n현재 기온: ' + $json.temp + '°C / 최고: ' + $json.tempMax + '°C\\n\\n☂️ 우산 챙기고, 야외 일정을 확인해주세요!' }}",
"otherOptions": {}
},
"id": "slack-008-05",
"name": "우천 Slack 알림 발송",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.2,
"position": [
1080,
280
]
}
],
"connections": {
"매일 오전 6시 트리거": {
"main": [
[
{
"node": "OpenWeatherMap 날씨 요청",
"type": "main",
"index": 0
}
]
]
},
"OpenWeatherMap 날씨 요청": {
"main": [
[
{
"node": "날씨 데이터 분석",
"type": "main",
"index": 0
}
]
]
},
"날씨 데이터 분석": {
"main": [
[
{
"node": "비 또는 눈 예보 확인",
"type": "main",
"index": 0
}
]
]
},
"비 또는 눈 예보 확인": {
"main": [
[
{
"node": "우천 Slack 알림 발송",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"timezone": "Asia/Seoul"
},
"meta": {
"chapter": 1,
"recipe": "008",
"title": "날씨 API 연동 → 우천 시 자동 알림",
"difficulty": "⭐⭐",
"estimatedTime": "30분",
"apps": [
"OpenWeatherMap API",
"Slack"
],
"workflowUrl": "www.koreaaitimes.com/books/n8n-vol2/recipe008"
}
}