Showing
1 changed file
with
25 additions
and
17 deletions
| ... | @@ -4,8 +4,8 @@ const secret_key_traffic = require('../keys/api_option_traffic').key; | ... | @@ -4,8 +4,8 @@ const secret_key_traffic = require('../keys/api_option_traffic').key; |
| 4 | 4 | ||
| 5 | const requesting = require('request'); | 5 | const requesting = require('request'); |
| 6 | 6 | ||
| 7 | -const lat = "37.54922931758";//"37.239795"; //weather 위도 | 7 | +const lat = "37.54922931758"; //weather 위도 |
| 8 | -const lon = "126.913415969472";//"127.083240"; //weather 경도 | 8 | +const lon = "126.913415969472"; //weather 경도 |
| 9 | const sido_num = "11"; //traffic 법정동 시도 코드 | 9 | const sido_num = "11"; //traffic 법정동 시도 코드 |
| 10 | const gugun_num = "440"; //traffic 법정동 시군구 코드 - 합정동 일대 | 10 | const gugun_num = "440"; //traffic 법정동 시군구 코드 - 합정동 일대 |
| 11 | const search_year = "2018074"; //traffic 검색을 원하는 연도 | 11 | const search_year = "2018074"; //traffic 검색을 원하는 연도 |
| ... | @@ -42,17 +42,18 @@ module.exports = (server, app) => { | ... | @@ -42,17 +42,18 @@ module.exports = (server, app) => { |
| 42 | json: true | 42 | json: true |
| 43 | }, | 43 | }, |
| 44 | //api에게 응답 받았을때 실행되는 callback function | 44 | //api에게 응답 받았을때 실행되는 callback function |
| 45 | - function (err, api_res, api_body) { | 45 | + function (err1, api_res1, api_body1) { |
| 46 | //err 존재시 promise reject 호출 | 46 | //err 존재시 promise reject 호출 |
| 47 | - if (err) reject(err); | 47 | + if (err1) reject(err1); |
| 48 | 48 | ||
| 49 | // api의 response이 있을경우 promise resolve 호출 | 49 | // api의 response이 있을경우 promise resolve 호출 |
| 50 | - if (api_res) { | 50 | + if (api_res1) { |
| 51 | console.log("calling weather api"); | 51 | console.log("calling weather api"); |
| 52 | - resolve(api_body); | 52 | + resolve(api_body1); |
| 53 | } | 53 | } |
| 54 | }); | 54 | }); |
| 55 | - }) | 55 | + |
| 56 | + }) //Promise | ||
| 56 | } | 57 | } |
| 57 | 58 | ||
| 58 | 59 | ||
| ... | @@ -63,12 +64,6 @@ module.exports = (server, app) => { | ... | @@ -63,12 +64,6 @@ module.exports = (server, app) => { |
| 63 | requesting.get({ | 64 | requesting.get({ |
| 64 | // api를 요청할 주소 -- 시크릿키,위도,경도 입력 | 65 | // api를 요청할 주소 -- 시크릿키,위도,경도 입력 |
| 65 | url: `http://apis.data.go.kr/B552061/${cate1}/${cate2}?ServiceKey=${secret_key_traffic}&searchYearCd=${search_year}&siDo=${sido_num}&guGun=${gugun_num}&type=json&numOfRows=1&pageNo=1`, | 66 | url: `http://apis.data.go.kr/B552061/${cate1}/${cate2}?ServiceKey=${secret_key_traffic}&searchYearCd=${search_year}&siDo=${sido_num}&guGun=${gugun_num}&type=json&numOfRows=1&pageNo=1`, |
| 66 | - //나중에 삭제 http://apis.data.go.kr/B552061/frequentzoneLg/getRestFrequentzoneLg?ServiceKey=XOLqI9tY4gVCdk1i2BoOM3EYmSUYqt8WlXUfIDSfD4RnNBrFwwthbNAtGOxoskP540JbUAzcnuABsydoE2U2dA%3D%3D&searchYearCd=2017&siDo=11&guGun=200&type=json&numOfRows=10&pageNo=1 | ||
| 67 | - //나중에 삭제 http://apis.data.go.kr/B552061/frequentzoneLg/getRestFrequentzoneLg?ServiceKey=XOLqI9tY4gVCdk1i2BoOM3EYmSUYqt8WlXUfIDSfD4RnNBrFwwthbNAtGOxoskP540JbUAzcnuABsydoE2U2dA%3D%3D&searchYearCd=2018074&siDo=11&guGun=440&type=json&numOfRows=10&pageNo=1 | ||
| 68 | - //sido = 11 gugun = 440 (마포구 합정동, 도화동, 도화동) | ||
| 69 | - //cate1 = frequentzoneLg | ||
| 70 | - //cate2 = getRestFrequentzoneLg | ||
| 71 | - //xml: true | ||
| 72 | json: true | 67 | json: true |
| 73 | }, | 68 | }, |
| 74 | //api에게 응답 받았을때 실행되는 callback function | 69 | //api에게 응답 받았을때 실행되는 callback function |
| ... | @@ -82,20 +77,26 @@ module.exports = (server, app) => { | ... | @@ -82,20 +77,26 @@ module.exports = (server, app) => { |
| 82 | resolve(api_body); | 77 | resolve(api_body); |
| 83 | } | 78 | } |
| 84 | }); | 79 | }); |
| 85 | - }) | 80 | + }) //Promise |
| 86 | } | 81 | } |
| 87 | 82 | ||
| 88 | const API_bundle = async () => { | 83 | const API_bundle = async () => { |
| 89 | - | ||
| 90 | try { | 84 | try { |
| 85 | + var order = 0; | ||
| 86 | + while (order < 2) { | ||
| 87 | + switch (order) { | ||
| 88 | + case 0: | ||
| 89 | + console.log("APIWait - WAITING FOR ALL API"); | ||
| 91 | Current_Weather = await req_API("current", "minutely"); //현재날씨 (분별) //when, what | 90 | Current_Weather = await req_API("current", "minutely"); //현재날씨 (분별) //when, what |
| 92 | Sensible_T = await req_API("index", "wct"); //체감온도 | 91 | Sensible_T = await req_API("index", "wct"); //체감온도 |
| 93 | Heat_index = await req_API("index", "heat"); //열지수 | 92 | Heat_index = await req_API("index", "heat"); //열지수 |
| 94 | Discomport_index = await req_API("index", "th"); //불쾌지수 | 93 | Discomport_index = await req_API("index", "th"); //불쾌지수 |
| 95 | Ultra_Violet_index = await req_API("index", "uv"); //자외선지수 | 94 | Ultra_Violet_index = await req_API("index", "uv"); //자외선지수 |
| 96 | - | ||
| 97 | Current_TrafficAcc = await req_API_traffic("frequentzoneLg", "getRestFrequentzoneLg"); //cate1, cate2 | 95 | Current_TrafficAcc = await req_API_traffic("frequentzoneLg", "getRestFrequentzoneLg"); //cate1, cate2 |
| 98 | - | 96 | + order = 1; |
| 97 | + break; | ||
| 98 | + case 1: | ||
| 99 | + console.log("APIDataProcess - CALLING INFO"); | ||
| 99 | info = { | 100 | info = { |
| 100 | heat: Heat_index.weather.wIndex.heatIndex[0].current.index, //열지수 | 101 | heat: Heat_index.weather.wIndex.heatIndex[0].current.index, //열지수 |
| 101 | sensible_temperature: Sensible_T.weather.wIndex.wctIndex[0].current.index, //체감온도 | 102 | sensible_temperature: Sensible_T.weather.wIndex.wctIndex[0].current.index, //체감온도 |
| ... | @@ -180,6 +181,13 @@ module.exports = (server, app) => { | ... | @@ -180,6 +181,13 @@ module.exports = (server, app) => { |
| 180 | db_total.query(sql, [client_send.time, client_send.wind, client_send.temperature, client_send.rain, client_send.death, client_send.trafficdeath, client_send.mhurt, client_send.lhurt, client_send.occurence], (err, result) => { | 181 | db_total.query(sql, [client_send.time, client_send.wind, client_send.temperature, client_send.rain, client_send.death, client_send.trafficdeath, client_send.mhurt, client_send.lhurt, client_send.occurence], (err, result) => { |
| 181 | if (err) console.log(err); | 182 | if (err) console.log(err); |
| 182 | }) | 183 | }) |
| 184 | + order = 2; | ||
| 185 | + break; | ||
| 186 | + default: | ||
| 187 | + order = 3; | ||
| 188 | + break; | ||
| 189 | + }//switch | ||
| 190 | + }; //while | ||
| 183 | 191 | ||
| 184 | } catch (err) { //promise err or try err catch | 192 | } catch (err) { //promise err or try err catch |
| 185 | console.log("================Error Occured !!================\n", err); | 193 | console.log("================Error Occured !!================\n", err); | ... | ... |
-
Please register or login to post a comment