Showing
1 changed file
with
81 additions
and
5 deletions
... | @@ -17,6 +17,8 @@ var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcs | ... | @@ -17,6 +17,8 @@ var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcs |
17 | var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/ | 17 | var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/ |
18 | 18 | ||
19 | //오늘의 날짜 구하기 | 19 | //오늘의 날짜 구하기 |
20 | +let base,tommorow; | ||
21 | + | ||
20 | let today=new Date(); | 22 | let today=new Date(); |
21 | let CurDay=today.getFullYear().toString(); | 23 | let CurDay=today.getFullYear().toString(); |
22 | if(today.getMonth()<9){ | 24 | if(today.getMonth()<9){ |
... | @@ -26,12 +28,18 @@ else{ | ... | @@ -26,12 +28,18 @@ else{ |
26 | CurDay+=(today.getMonth()+1).toString(); | 28 | CurDay+=(today.getMonth()+1).toString(); |
27 | } | 29 | } |
28 | if(today.getDate()<10){ | 30 | if(today.getDate()<10){ |
31 | + base=CurDay+"0"+(today.getDate()-1).toString(); | ||
32 | + tommorow=CurDay+"0"+(today.getDate()+1).toString(); | ||
33 | + | ||
29 | CurDay+="0"+today.getDate().toString(); | 34 | CurDay+="0"+today.getDate().toString(); |
30 | } | 35 | } |
31 | else{ | 36 | else{ |
37 | + base=CurDay+(today.getDate()-1).toString(); | ||
38 | + tommorow=CurDay+(today.getDate()+1).toString(); | ||
39 | + | ||
32 | CurDay+=today.getDate().toString(); | 40 | CurDay+=today.getDate().toString(); |
33 | } | 41 | } |
34 | - | 42 | +console.log(tommorow); |
35 | //nx,ny구하기 | 43 | //nx,ny구하기 |
36 | const xlsx=require('xlsx') | 44 | const xlsx=require('xlsx') |
37 | const excel=xlsx.readFile('location.xlsx'); | 45 | const excel=xlsx.readFile('location.xlsx'); |
... | @@ -62,8 +70,8 @@ app.post('/api/weather',(req,res)=>{ | ... | @@ -62,8 +70,8 @@ app.post('/api/weather',(req,res)=>{ |
62 | queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ | 70 | queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ |
63 | queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ | 71 | queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ |
64 | queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ | 72 | queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ |
65 | - queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */ | 73 | + queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(base); /* */ |
66 | - queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */ | 74 | + queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2300'); /* */ |
67 | queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/ | 75 | queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/ |
68 | queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/ | 76 | queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/ |
69 | 77 | ||
... | @@ -84,8 +92,76 @@ app.post('/api/weather',(req,res)=>{ | ... | @@ -84,8 +92,76 @@ app.post('/api/weather',(req,res)=>{ |
84 | } | 92 | } |
85 | let result=[]; | 93 | let result=[]; |
86 | i=0; | 94 | i=0; |
95 | + let Json; | ||
96 | + while(i<a.length){ | ||
97 | + if(a[i].fcstValue<=8){ | ||
98 | + Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:0}; | ||
99 | + } | ||
100 | + else if(a[i].fcstValue>8 && a[i].fcstValue<=12){ | ||
101 | + Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:1}; | ||
102 | + } | ||
103 | + else if(a[i].fcstValue>12 && a[i].fcstValue<=18){ | ||
104 | + Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:2}; | ||
105 | + } | ||
106 | + else if(a[i].fcstValue>18 && a[i].fcstValue<=23){ | ||
107 | + Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:3}; | ||
108 | + } | ||
109 | + else{ | ||
110 | + Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:4}; | ||
111 | + }; | ||
112 | + result.push(Json); | ||
113 | + i+=2; | ||
114 | + } | ||
115 | + res.json(result); | ||
116 | + });//pop:강수확률 tmp:한시간 기온 | ||
117 | +}); | ||
118 | + | ||
119 | +app.post('/api/tommorow',(req,res)=>{ | ||
120 | + const nx = req.body.dotX; | ||
121 | + const ny = req.body.dotY; | ||
122 | + | ||
123 | + queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ | ||
124 | + queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ | ||
125 | + queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ | ||
126 | + queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */ | ||
127 | + queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */ | ||
128 | + queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/ | ||
129 | + queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/ | ||
130 | + | ||
131 | + request({ | ||
132 | + url: url + queryParams, | ||
133 | + method: 'GET' | ||
134 | + }, function (error, response, body) { | ||
135 | + let ex=JSON.parse(body); | ||
136 | + let item=ex.response.body.items.item; | ||
137 | + | ||
138 | + let i=0; | ||
139 | + let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; | ||
140 | + while(item[i].fcstDate==tommorow||item[i].fcstDate==CurDay){ | ||
141 | + if((item[i].category=='POP' || item[i].category=='TMP') && item[i].fcstDate==tommorow){ | ||
142 | + a.push(item[i]); | ||
143 | + } | ||
144 | + i+=1; | ||
145 | + } | ||
146 | + let result=[]; | ||
147 | + i=0; | ||
148 | + let Json; | ||
87 | while(i<a.length){ | 149 | while(i<a.length){ |
88 | - let Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue}; | 150 | + if(a[i].fcstValue<=8){ |
151 | + Json={today:tommorow,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:0}; | ||
152 | + } | ||
153 | + else if(a[i].fcstValue>8 && a[i].fcstValue<=12){ | ||
154 | + Json={today:tommorow,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:1}; | ||
155 | + } | ||
156 | + else if(a[i].fcstValue>12 && a[i].fcstValue<=18){ | ||
157 | + Json={today:tommorow,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:2}; | ||
158 | + } | ||
159 | + else if(a[i].fcstValue>18 && a[i].fcstValue<=23){ | ||
160 | + Json={today:tommorow,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:3}; | ||
161 | + } | ||
162 | + else{ | ||
163 | + Json={today:tommorow,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:4}; | ||
164 | + }; | ||
89 | result.push(Json); | 165 | result.push(Json); |
90 | i+=2; | 166 | i+=2; |
91 | } | 167 | } |
... | @@ -93,4 +169,4 @@ app.post('/api/weather',(req,res)=>{ | ... | @@ -93,4 +169,4 @@ app.post('/api/weather',(req,res)=>{ |
93 | });//pop:강수확률 tmp:한시간 기온 | 169 | });//pop:강수확률 tmp:한시간 기온 |
94 | }); | 170 | }); |
95 | 171 | ||
96 | -app.listen(4000, () => console.log('Server On 5000')); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
172 | +app.listen(4000, () => console.log('Server On 4000')); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment