기상청 날씨 API (사용 X -> 최저, 최고기온 정보 없음
)
End Point
인증키
R0JxlwfVJ5AiJuhDSHh0q0C1WpRnnze0g1nSOAs7dYjmDFvG3XBpbK4d4Ufjx0gBHd3lnlGBYpjS2JnN0Lt/ZA==
호출 예시 - GET
응답 예시
JSON
{ "response": { "header": { "resultCode": "00", "resultMsg": "NORMAL_SERVICE" }, "body": { "dataType": "JSON", "items": { "item": [ { "baseDate": "20211018", "baseTime": "0500", "category": "TMP", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "5", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "UUU", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "-1.2", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "VVV", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "0.6", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "VEC", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "115", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "WSD", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "1.4", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "SKY", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "1", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "PTY", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "0", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "POP", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "0", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "WAV", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "0", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "PCP", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "강수없음", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "REH", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "70", "nx": 61, "ny": 126 }, { "baseDate": "20211018", "baseTime": "0500", "category": "SNO", "fcstDate": "20211018", "fcstTime": "0600", "fcstValue": "적설없음", "nx": 61, "ny": 126 } ] }, "pageNo": 1, "numOfRows": 12, "totalCount": 809 } } }
- base_time은 0200, 0500 ... 2300 (1일 8회) 값으로 조회할 수 있습니다.
- API 제공시간은 base_time보다 10분 뒤 입니다. 02:10, 05:10 ... 23:10
비고
- 한 페이지 결과 수
12
, 페이지 번호를1
로 한 이유 → 자료구분 문자가 12가지 종류 이기 때문에 각 시간별로 12가지의 정보를 얻을 수 있습니다.
- 😡😡😡여러분 지금 문제가 발생했습니다...... 문서상 존재하는 자료구분문자는 총
14
가지 인데 API에서 실제 조회되는 자료구분문자 수는12
가지여서 확인해보니 가장 중요한일 최저기온
과일 최고기온
2가지가 없습니다.......... 하................
- 그래서 다른 API 찾는 중 입니다 → 찾았어요
현재 날씨 API
설명
10분 마다 실시간 날씨를 불러오는 API
End Point
인증키
53fc7d023d32938ee6fb55f2853ab8fb
요청 파라미터
요청 예시
응답 예시
{ "coord": { "lon": 126.9778, "lat": 37.5683 }, "weather": [ { "id": 500, "main": "Rain", "description": "light rain", "icon": "10n" }, { "id": 701, "main": "Mist", "description": "mist", "icon": "50n" } ], "base": "stations", "main": { "temp": 10.73, "feels_like": 10.29, "temp_min": 8.42, "temp_max": 10.76, "pressure": 1021, "humidity": 93 }, "visibility": 3500, "wind": { "speed": 2.57, "deg": 300 }, "rain": { "1h": 0.56 }, "clouds": { "all": 90 }, "dt": 1634569414, "sys": { "type": 1, "id": 8105, "country": "KR", "sunrise": 1634593415, "sunset": 1634633417 }, "timezone": 32400, "id": 1835848, "name": "Seoul", "cod": 200 }
날씨 코드
"weather"
값은 배열로 넘어오고 하나 이상의 기상 조건을 충족하면 여러 항목들이 담깁니다.
"weather"
요소들의"id"
값에 따라 메인 날씨가 구분되어 있습니다.
- 그래서 저희는
"weather"
배열의 첫 번째 요소의"main"
값을 enum으로 선언해 놓고 그에 맞게 날씨를 보여주면 될듯 합니다. (요청할 때lang
을kr
하면 한글로 넘어오긴 하지만 뭔가 번역이 이상해서..)
- https://openweathermap.org/weather-conditions 여기에서 자세한 날씨별 코드값을 볼 수 있습니다.
- 2xx : Thunderstorm
- 3xx : Drizzle
- 5xx : Rain
- 6xx : Snow
- 7xx : Atmosphere
- 800 : Clear
- 80x : Clouds
시간
- 시간의 값은
"dt"
필드에 담겨오는데 Unix, UTC 형태의 값으로 옵니다. 그래서new Date(dt * 1000)
을 하면 현재 날짜와 시간을 구할 수 있습니다.
과거 날씨 API
설명
5일 전 까지의 날씨 정보를 조회하는 API.
저희는 현재시간 기준 24시간 전의 온도를 조회하여 활용할 수 있습니다.
End Point
인증키
53fc7d023d32938ee6fb55f2853ab8fb
요청 파라미터
요청 파라미터는 실시간 날짜와 거의 비슷하며 차이점은 아래와 같습니다.
- 위치값은
"q"
를 활용한 도시 이름을 사용할 수 없고"lat"
,"lon"
을 사용해야 합니다. (위도, 경도)
"lat"
: 37.56 ,"lon"
: 126.97 은 서울을 의미합니다.
"dt"
: 조회 할 시간의 Unix, UTC 값을 의미합니다. 저희는 하루 전날 온도값을 구해야하기 때문에 현재"dt"
에서"24 * 60 * 60"
를 뺀 값을 요청하면 됩니다.
응답 예시
{ "lat": 37.56, "lon": 126.97, "timezone": "Asia/Seoul", "timezone_offset": 32400, "current": { "dt": 1634481951, "sunrise": 1634420501, "sunset": 1634460782, "temp": 3.94, "feels_like": 3.94, "pressure": 1027, "humidity": 51, "dew_point": -4.67, "uvi": 0, "clouds": 0, "visibility": 10000, "wind_speed": 0.51, "wind_deg": 60, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01n" } ] }, "hourly": [ { "dt": 1634428800, "temp": 4.43, "feels_like": 0.81, "pressure": 1031, "humidity": 34, "dew_point": -8.95, "uvi": 0, "clouds": 0, "visibility": 10000, "wind_speed": 4.63, "wind_deg": 330, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01d" } ] }, ... 생략 { "dt": 1634511600, "temp": 4.9, "feels_like": 2.72, "pressure": 1025, "humidity": 56, "dew_point": -2.77, "uvi": 0, "clouds": 0, "visibility": 10000, "wind_speed": 2.57, "wind_deg": 180, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01d" } ] } ] }
- 저희는
"current"
의"temp"
값만 활용하면 될 것 같습니다.