곽태식

예보 api 추가 완료

1 const db = require('./db.js'); 1 const db = require('./db.js');
2 const secret_key = require('../keys/api_option').weather_key; 2 const secret_key = require('../keys/api_option').weather_key;
3 -//const traffic_key = require('../keys/api_option').traffic_key; 3 +const traffic_key = require('../keys/api_option').traffic_key;
4 const requesting = require('request'); 4 const requesting = require('request');
5 const lat = "37.239795"; 5 const lat = "37.239795";
6 const lon = "127.083240"; 6 const lon = "127.083240";
...@@ -56,27 +56,27 @@ module.exports = (server, app) => { ...@@ -56,27 +56,27 @@ module.exports = (server, app) => {
56 } 56 }
57 57
58 // 교통사고정보를 받아오는 함수 58 // 교통사고정보를 받아오는 함수
59 -// const req_traffic_API = (year) => { 59 + const req_traffic_API = (year) => {
60 //async await 사용하기 위하여 promise 사용 60 //async await 사용하기 위하여 promise 사용
61 -// return new Promise((resolve, reject) => { 61 + return new Promise((resolve, reject) => {
62 -// requesting.get({ 62 + requesting.get({
63 -// // api를 요청할 주소 -- 시크릿키,위도,경도 입력 63 + // api를 요청할 주소 -- 시크릿키,위도,경도 입력
64 -// url: `http://taas.koroad.or.kr/data/rest/accident/death?authKey=${traffic_key}&searchYear=${year}&siDo=${city}&guGun=${town}&type=json`, 64 + url: `http://taas.koroad.or.kr/data/rest/accident/death?authKey=${traffic_key}&searchYear=${year}&siDo=${city}&guGun=${town}&type=json`,
65 -// json: true 65 + json: true
66 -// }, 66 + },
67 -// //api에게 응답 받았을때 실행되는 callback function 67 + //api에게 응답 받았을때 실행되는 callback function
68 -// function (err, api_res, api_body) { 68 + function (err, api_res, api_body) {
69 -// //err 존재시 promise reject 호출 69 + //err 존재시 promise reject 호출
70 -// if (err) reject(err); 70 + if (err) reject(err);
71 -// 71 +
72 -// // api의 response이 있을경우 promise resolve 호출 72 + // api의 response이 있을경우 promise resolve 호출
73 -// if (api_res) { 73 + if (api_res) {
74 -// console.log("calling traffic api"); 74 + console.log("calling traffic api");
75 -// resolve(api_body); 75 + resolve(api_body);
76 -// } 76 + }
77 -// }); 77 + });
78 -// }) 78 + })
79 -// } 79 + }
80 const API_bundle = async () => { 80 const API_bundle = async () => {
81 81
82 try { 82 try {
...@@ -89,8 +89,8 @@ module.exports = (server, app) => { ...@@ -89,8 +89,8 @@ module.exports = (server, app) => {
89 Day3_Weather = await req_API("forecast","3days"); //3일예보(단기예보) 89 Day3_Weather = await req_API("forecast","3days"); //3일예보(단기예보)
90 90
91 // 사용자의 생일에 따라서 다른 년도의 교통사고정보를 가져옴. 91 // 사용자의 생일에 따라서 다른 년도의 교통사고정보를 가져옴.
92 -// const year = year_start + (client_birth % (year_range+1)); 92 + const year = year_start + (client_birth % (year_range+1));
93 -// Traffic_Accident = await req_traffic_API(year); //교통사고정보 93 + Traffic_Accident = await req_traffic_API(year); //교통사고정보
94 94
95 95
96 info = { 96 info = {
...@@ -107,22 +107,40 @@ module.exports = (server, app) => { ...@@ -107,22 +107,40 @@ module.exports = (server, app) => {
107 typhoon: Current_Weather.common.stormYn, //현재 태풍 107 typhoon: Current_Weather.common.stormYn, //현재 태풍
108 time: Current_Weather.weather.minutely[0].timeObservation, // 불러온 시각 108 time: Current_Weather.weather.minutely[0].timeObservation, // 불러온 시각
109 109
110 - Forecast_64W: Day3_Weather.weather.forecast3days[0].fcst3hour.wind.wspd61hour, 110 + Forecast_1dayHeat: Heat_index.weather.wIndex.heatIndex[0].forecast.index25hour, //열지수 예보
111 - Forecast_25W: Day3_Weather.weather.forecast3days[0].fcst3hour.wind.wspd25hour, 111 + Forecast_2dayHeat: Heat_index.weather.wIndex.heatIndex[0].forecast.index49hour,
112 - Forecast_46W: Day3_Weather.weather.forecast3days[0].fcst3hour.wind.wspd46hour, 112 + Forecast_laterHeat: Heat_index.weather.wIndex.heatIndex[0].forecast.index52hour,
113 +
114 + Forecast_1daySensible: Sensible_T.weather.wIndex.wctIndex[0].forecast.index25hour,// 체감온도 예보
115 + Forecast_2daySensible: Sensible_T.weather.wIndex.wctIndex[0].forecast.index49hour,
116 + Forecast_laterSensible: Sensible_T.weather.wIndex.wctIndex[0].forecast.index52hour,
113 117
114 - Forecast_25R: Day3_Weather.weather.forecast3days[0].fcst3hour.precipitation.prob25hour, 118 + Forecast_1dayDiscomport: Discomport_index.weather.wIndex.thIndex[0].forecast.index25hour, //불쾌지수
115 - Forecast_46R: Day3_Weather.weather.forecast3days[0].fcst3hour.precipitation.prob46hour, 119 + Forecast_2dayDiscomport: Discomport_index.weather.wIndex.thIndex[0].forecast.index49hour,
116 - Forecast_64R: Day3_Weather.weather.forecast3days[0].fcst3hour.precipitation.prob64hour, 120 + Forecast_laterDiscomport: Discomport_index.weather.wIndex.thIndex[0].forecast.index52hour,
121 +
122 + Forecast_warning: Day3_Weather.common.alertYn, //특보 예보
123 + Forecast_typhoon: Day3_Weather.common.stormYn, //태풍 예보
124 +
125 + Forecast_1dayW: Day3_Weather.weather.forecast3days[0].fcst3hour.wind.wspd25hour,//바람속도 예보
126 + Forecast_2dayW: Day3_Weather.weather.forecast3days[0].fcst3hour.wind.wspd49hour,
127 + Forecast_laterW: Day3_Weather.weather.forecast3days[0].fcst3hour.wind.wspd52hour,
128 +
129 + Forecast_1dayR: Day3_Weather.weather.forecast3days[0].fcst3hour.precipitation.prob25hour, //강수량 예보
130 + Forecast_2dayR: Day3_Weather.weather.forecast3days[0].fcst3hour.precipitation.prob49hour,
131 + Forecast_laterR: Day3_Weather.weather.forecast3days[0].fcst3hour.precipitation.prob52hour,
117 132
118 - Forecast_25S: Day3_Weather.weather.forecast3days[0].fcst3hour.sky.code25hour, 133 + Forecast_1dayS: Day3_Weather.weather.forecast3days[0].fcst3hour.sky.code25hour, //하늘상태 예보
119 - Forecast_46S: Day3_Weather.weather.forecast3days[0].fcst3hour.sky.code46hour, 134 + Forecast_2dayS: Day3_Weather.weather.forecast3days[0].fcst3hour.sky.code46hour,
120 - Forecast_64S: Day3_Weather.weather.forecast3days[0].fcst3hour.sky.code64hour, 135 + Forecast_laterS: Day3_Weather.weather.forecast3days[0].fcst3hour.sky.code64hour,
121 -// traffic: Traffic_Accident.totalCount, // 교통사고 발생횟수 136 +
137 +
138 +
139 + traffic: Traffic_Accident.totalCount, // 교통사고 발생횟수
122 death_prob: 0 //확률 140 death_prob: 0 //확률
123 } 141 }
124 console.log("API INFO \n", info); 142 console.log("API INFO \n", info);
125 -// console.log("Traffic count:", info.traffic); 143 + console.log("Traffic count:", info.traffic);
126 144
127 145
128 146
......