김건희

[Update] Weather Files

This diff could not be displayed because it is too large.
...@@ -10,11 +10,7 @@ ...@@ -10,11 +10,7 @@
10 "express": "^4.18.1", 10 "express": "^4.18.1",
11 "express-session": "^1.17.3", 11 "express-session": "^1.17.3",
12 "http-proxy-middleware": "^2.0.6", 12 "http-proxy-middleware": "^2.0.6",
13 -<<<<<<< HEAD
14 - "mongoose": "^6.3.4",
15 -=======
16 "mongoose": "^6.3.3", 13 "mongoose": "^6.3.3",
17 ->>>>>>> origin/weather
18 "nodemon": "^2.0.16", 14 "nodemon": "^2.0.16",
19 "react": "^18.1.0", 15 "react": "^18.1.0",
20 "react-dom": "^18.1.0", 16 "react-dom": "^18.1.0",
......
...@@ -2,11 +2,13 @@ var request = require('request'); ...@@ -2,11 +2,13 @@ var request = require('request');
2 let express = require('express'); 2 let express = require('express');
3 let app=express(); 3 let app=express();
4 let bodyParser = require('body-parser'); 4 let bodyParser = require('body-parser');
5 -let session = require('express-session') 5 +let session = require('express-session');
6 +let cors = require('cors');
6 7
7 app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})) 8 app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
8 app.use(bodyParser.urlencoded({ extended: false })); 9 app.use(bodyParser.urlencoded({ extended: false }));
9 app.use(bodyParser.json()); 10 app.use(bodyParser.json());
11 +app.use(cors());
10 //nx,ny구하기 12 //nx,ny구하기
11 13
12 //변수들 14 //변수들
...@@ -14,10 +16,21 @@ let curaddress; ...@@ -14,10 +16,21 @@ let curaddress;
14 var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'; 16 var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
15 var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/ 17 var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/
16 18
17 - 19 +//오늘의 날짜 구하기
18 - 20 +let today=new Date();
19 - 21 +let CurDay=today.getFullYear().toString();
20 - 22 +if(today.getMonth()<9){
23 + CurDay+="0"+(today.getMonth()+1).toString();
24 +}
25 +else{
26 + CurDay+=(today.getMonth()+1).toString();
27 +}
28 +if(today.getDate()<10){
29 + CurDay+="0"+today.getDate().toString();
30 +}
31 +else{
32 + CurDay+=today.getDate().toString();
33 +}
21 34
22 //nx,ny구하기 35 //nx,ny구하기
23 const xlsx=require('xlsx') 36 const xlsx=require('xlsx')
...@@ -25,143 +38,59 @@ const excel=xlsx.readFile('location.xlsx'); ...@@ -25,143 +38,59 @@ const excel=xlsx.readFile('location.xlsx');
25 const sheet=excel.SheetNames[0]; 38 const sheet=excel.SheetNames[0];
26 const first=excel.Sheets[sheet]; 39 const first=excel.Sheets[sheet];
27 const jsonData=xlsx.utils.sheet_to_json(first,{defval:""}); 40 const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
28 -let nx,ny,add; 41 +let nx,ny;
29 -app.post('/address', (req, res) => { 42 +app.post('/api/address', (req, res) => {
30 let i=0; 43 let i=0;
31 while(i<3788){ 44 while(i<3788){
32 if(jsonData[i].address1==req.body.address1 && jsonData[i].address2==req.body.address2 && jsonData[i].address3==req.body.address3){ 45 if(jsonData[i].address1==req.body.address1 && jsonData[i].address2==req.body.address2 && jsonData[i].address3==req.body.address3){
33 nx=jsonData[i].nx; 46 nx=jsonData[i].nx;
34 ny=jsonData[i].ny; 47 ny=jsonData[i].ny;
35 curaddress=jsonData[i]; 48 curaddress=jsonData[i];
36 - queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ 49 + res.json({nx, ny});
37 - queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
38 - queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
39 - queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */
40 - queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */
41 - queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/
42 - queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/
43 - res.send("좌표는 "+nx+" "+ny+"입니다.");
44 - add=req.body.address1+' '+req.body.address2+' '+req.body.address3;
45 break; 50 break;
46 } 51 }
47 i+=1; 52 i+=1;
48 } 53 }
49 }); 54 });
50 55
51 -
52 -//오늘의 날짜 구하기
53 -let today=new Date();
54 -let CurDay=today.getFullYear().toString();
55 -if(today.getMonth()<9){
56 - CurDay+="0"+(today.getMonth()+1).toString();
57 -}
58 -else{
59 - CurDay+=(today.getMonth()+1).toString();
60 -}
61 -if(today.getDate()<10){
62 - CurDay+="0"+today.getDate().toString();
63 -}
64 -else{
65 - CurDay+=today.getDate().toString();
66 -}
67 -
68 -
69 -
70 -
71 -
72 -
73 -
74 -
75 let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; 56 let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
76 //입력받기 57 //입력받기
77 -app.post('/mainpage',(req,res)=>{ 58 +app.post('/api/weather',(req,res)=>{
78 - request({ 59 + const nx = req.body.dotX;
79 - url: url + queryParams, 60 + const ny = req.body.dotY;
80 - method: 'GET' 61 +
81 - }, function (error, response, body) { 62 + queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
82 - let ex=JSON.parse(body); 63 + queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
83 - let item=ex.response.body.items.item; 64 + queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
84 - // console.log(items); 65 + queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */
85 - let i=0; 66 + queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */
86 - let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; 67 + queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/
87 - while(item[i].fcstDate==CurDay){ 68 + queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/
88 - if(item[i].category=='POP' || item[i].category=='TMP'){ 69 +
89 - a.push(item[i]); 70 + request({
90 - } 71 + url: url + queryParams,
91 - i+=1; 72 + method: 'GET'
92 - } 73 + }, function (error, response, body) {
93 - let result=[]; 74 + let ex=JSON.parse(body);
94 - i=0; 75 + let item=ex.response.body.items.item;
95 - // while(i<a.length){ 76 +
96 - // let str=CurDay+' '+add+'의 '+a[i].fcstTime[0]+a[i].fcstTime[1]+'시 기온은 '+a[i].fcstValue+'이고, 강수확률은 '+a[i+1].fcstValue+'이다.'; 77 + let i=0;
97 - // result.push(str); 78 + let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
98 - // i+=2; 79 + while(item[i].fcstDate==CurDay){
99 - //}//정보를 string으로 저장. 80 + if(item[i].category=='POP' || item[i].category=='TMP'){
100 - while(i<a.length){ 81 + a.push(item[i]);
101 - let Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue}; 82 + }
102 - result.push(Json); 83 + i+=1;
103 - i+=2; 84 + }
104 - }//정보를 Json형식으로 저장. 85 + let result=[];
105 - //return result를 해주고 싶은데 방법을 잘 모르겠음 86 + i=0;
106 - res.send(result); 87 + while(i<a.length){
107 - });//pop:강수확률 tmp:한시간 기온 88 + let Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue};
108 -}); 89 + result.push(Json);
109 - 90 + i+=2;
110 - 91 + }
111 -//시간대별 괜찮은 옷 92 + res.json(result);
112 -app.post('/clothes', (req, res) => { 93 + });//pop:강수확률 tmp:한시간 기온
113 - request({
114 - url: url + queryParams,
115 - method: 'GET'
116 - }, function (error, response, body) {
117 - let ex=JSON.parse(body);
118 - let item=ex.response.body.items.item;
119 - // console.log(items);
120 - let i=0;
121 - let a=[];
122 - while(item[i].fcstDate==CurDay){
123 - if(item[i].category=='POP' || item[i].category=='TMP'){
124 - a.push(item[i]);
125 - }
126 - i+=1;
127 - }
128 - let result=[];
129 - i=0;
130 - let Json={};
131 - while(i<a.length){
132 - let umb=0
133 - if(Number(a[i+1].fcstValue)>0){
134 - umb=1// 비가올 확률이 있을 시 우산을 챙김
135 - };
136 - if(Number(a[i].fcstValue)>=28){
137 - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],top:"반팔, 민소매, 원피스",pants:"반바지",umbrella:umb};
138 - }
139 - else if(Number(a[i].fcstValue)<28 && Number(a[i].fcstValue)>=23){
140 - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],top:"반팔, 얇은 셔츠",pants:"반바지, 면바지",umbrella:umb};
141 - }
142 - else if(Number(a[i].fcstValue)<23 && Number(a[i].fcstValue)>=20){
143 - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],top:"얇은 가디건, 긴팔",pants:"면바지, 청바지",umbrella:umb};
144 - }
145 - else if(Number(a[i].fcstValue)<20 && Number(a[i].fcstValue)>=17){
146 - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],top:"얇은 니트, 맨투맨, 가디건",pants:"면바지",umbrella:umb};
147 - }
148 - else if(Number(a[i].fcstValue)<17 && Number(a[i].fcstValue)>=12){
149 - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],top:"자켓, 가디건, 야상",pants:"스타킹, 청바지, 면바지",umbrella:umb};
150 - }
151 - else if(Number(a[i].fcstValue)<12 && Number(a[i].fcstValue)>=9){
152 - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],top:"자켓, 트렌치코트, 야상, 니트",pants:"청바지, 스타킹",umbrella:umb};
153 - }
154 - else if(Number(a[i].fcstValue)<9 && Number(a[i].fcstValue)>=5){
155 - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],top:"코트, 가죽자켓, 히트텍, 니트",pants:"청바지, 레깅스",umbrella:umb};
156 - }
157 - else{
158 - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],top:"패딩, 두꺼운코트, 목도리",pants:"기모제품, 내복바지",umbrella:umb};
159 - }
160 - result.push(Json);
161 - i+=2;
162 - }
163 - res.send(result);
164 - });
165 }); 94 });
166 95
167 -app.listen(4000, () => console.log('Server On 4000'));
...\ No newline at end of file ...\ No newline at end of file
96 +app.listen(4000, () => console.log('Server On 5000'));
...\ No newline at end of file ...\ No newline at end of file
......