Showing
1 changed file
with
44 additions
and
1 deletions
... | @@ -10,7 +10,7 @@ const axios = require('axios') | ... | @@ -10,7 +10,7 @@ const axios = require('axios') |
10 | // 예) 6/2일 오후 4시 호출 => 6/2일 정오 날씨 반환 (정오 기준이므로) | 10 | // 예) 6/2일 오후 4시 호출 => 6/2일 정오 날씨 반환 (정오 기준이므로) |
11 | // 온도의 경우 단위는 섭씨입니다. | 11 | // 온도의 경우 단위는 섭씨입니다. |
12 | 12 | ||
13 | -/*example | 13 | +/*example - forecast |
14 | 14 | ||
15 | "dt": 1653620400, | 15 | "dt": 1653620400, |
16 | "sunrise": 1653596132, | 16 | "sunrise": 1653596132, |
... | @@ -52,6 +52,34 @@ const axios = require('axios') | ... | @@ -52,6 +52,34 @@ const axios = require('axios') |
52 | "uvi": 7.71 //The maximum value of UV index for the day | 52 | "uvi": 7.71 //The maximum value of UV index for the day |
53 | 53 | ||
54 | */ | 54 | */ |
55 | + | ||
56 | +/*example - current | ||
57 | +{ | ||
58 | + "dt": 1653989440, | ||
59 | + "sunrise": 1653941622, | ||
60 | + "sunset": 1653993914, | ||
61 | + "temp": 23.74, | ||
62 | + "feels_like": 22.82, | ||
63 | + "pressure": 1008, | ||
64 | + "humidity": 25, | ||
65 | + "dew_point": 2.56, | ||
66 | + "uvi": 0.17, | ||
67 | + "clouds": 20, | ||
68 | + "visibility": 10000, | ||
69 | + "wind_speed": 5.66, | ||
70 | + "wind_deg": 300, | ||
71 | + "weather": [ | ||
72 | + { | ||
73 | + "id": 801, | ||
74 | + "main": "Clouds", | ||
75 | + "description": "few clouds", | ||
76 | + "icon": "02d" | ||
77 | + } | ||
78 | + ] | ||
79 | + } | ||
80 | + | ||
81 | + | ||
82 | +*/ | ||
55 | async function get_weather_forecast(date) { | 83 | async function get_weather_forecast(date) { |
56 | const lat = 37.24764302276268 //위도 | 84 | const lat = 37.24764302276268 //위도 |
57 | const lon = 127.0783992268606 //경도 | 85 | const lon = 127.0783992268606 //경도 |
... | @@ -62,6 +90,16 @@ async function get_weather_forecast(date) { | ... | @@ -62,6 +90,16 @@ async function get_weather_forecast(date) { |
62 | return await axios.default.get(target).then(it => { return extract_from(date, it.data) }) | 90 | return await axios.default.get(target).then(it => { return extract_from(date, it.data) }) |
63 | } | 91 | } |
64 | 92 | ||
93 | +async function get_weather_current() { | ||
94 | + const lat = 37.24764302276268 //위도 | ||
95 | + const lon = 127.0783992268606 //경도 | ||
96 | + const api_key = "336ddd01d3d6f78782eed90d3921bc7e" | ||
97 | + | ||
98 | + const target = `https://api.openweathermap.org/data/2.5/onecall?lat=${lat}&lon=${lon}&exclude=minutely,hourly,alerts&appid=${api_key}&units=metric` | ||
99 | + | ||
100 | + return await axios.default.get(target).then(it => { return extract_current(it.data) }) | ||
101 | +} | ||
102 | + | ||
65 | function extract_from(date, json_response) { | 103 | function extract_from(date, json_response) { |
66 | const target_timestamp = Math.floor(date.getTime() / 1000) | 104 | const target_timestamp = Math.floor(date.getTime() / 1000) |
67 | 105 | ||
... | @@ -70,6 +108,10 @@ function extract_from(date, json_response) { | ... | @@ -70,6 +108,10 @@ function extract_from(date, json_response) { |
70 | return json_response.daily[target_index] | 108 | return json_response.daily[target_index] |
71 | } | 109 | } |
72 | 110 | ||
111 | +function extract_current(json_response) { | ||
112 | + return json_response.current | ||
113 | +} | ||
114 | + | ||
73 | function find_min_index(array) { | 115 | function find_min_index(array) { |
74 | let lowest_index = 0 | 116 | let lowest_index = 0 |
75 | for (var i = 0; i < array.length; i++) { | 117 | for (var i = 0; i < array.length; i++) { |
... | @@ -82,3 +124,4 @@ function find_min_index(array) { | ... | @@ -82,3 +124,4 @@ function find_min_index(array) { |
82 | } | 124 | } |
83 | 125 | ||
84 | module.exports.get_weather_forecast = get_weather_forecast | 126 | module.exports.get_weather_forecast = get_weather_forecast |
127 | +module.exports.get_weather_current = get_weather_current | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment