김건희

[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,41 +16,6 @@ let curaddress; ...@@ -14,41 +16,6 @@ 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 -
18 -
19 -
20 -
21 -
22 -//nx,ny구하기
23 -const xlsx=require('xlsx')
24 -const excel=xlsx.readFile('location.xlsx');
25 -const sheet=excel.SheetNames[0];
26 -const first=excel.Sheets[sheet];
27 -const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
28 -let nx,ny,add;
29 -app.post('/address', (req, res) => {
30 - let i=0;
31 - while(i<3788){
32 - if(jsonData[i].address1==req.body.address1 && jsonData[i].address2==req.body.address2 && jsonData[i].address3==req.body.address3){
33 - nx=jsonData[i].nx;
34 - ny=jsonData[i].ny;
35 - curaddress=jsonData[i];
36 - queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
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;
46 - }
47 - i+=1;
48 - }
49 -});
50 -
51 -
52 //오늘의 날짜 구하기 19 //오늘의 날짜 구하기
53 let today=new Date(); 20 let today=new Date();
54 let CurDay=today.getFullYear().toString(); 21 let CurDay=today.getFullYear().toString();
...@@ -65,60 +32,50 @@ else{ ...@@ -65,60 +32,50 @@ else{
65 CurDay+=today.getDate().toString(); 32 CurDay+=today.getDate().toString();
66 } 33 }
67 34
68 - 35 +//nx,ny구하기
69 - 36 +const xlsx=require('xlsx')
70 - 37 +const excel=xlsx.readFile('location.xlsx');
71 - 38 +const sheet=excel.SheetNames[0];
72 - 39 +const first=excel.Sheets[sheet];
73 - 40 +const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
74 - 41 +let nx,ny;
75 -let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; 42 +app.post('/api/address', (req, res) => {
76 -//입력받기
77 -app.post('/mainpage',(req,res)=>{
78 - request({
79 - url: url + queryParams,
80 - method: 'GET'
81 - }, function (error, response, body) {
82 - let ex=JSON.parse(body);
83 - let item=ex.response.body.items.item;
84 - // console.log(items);
85 let i=0; 43 let i=0;
86 - let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; 44 + while(i<3788){
87 - while(item[i].fcstDate==CurDay){ 45 + if(jsonData[i].address1==req.body.address1 && jsonData[i].address2==req.body.address2 && jsonData[i].address3==req.body.address3){
88 - if(item[i].category=='POP' || item[i].category=='TMP'){ 46 + nx=jsonData[i].nx;
89 - a.push(item[i]); 47 + ny=jsonData[i].ny;
48 + curaddress=jsonData[i];
49 + res.json({nx, ny});
50 + break;
90 } 51 }
91 i+=1; 52 i+=1;
92 } 53 }
93 - let result=[];
94 - i=0;
95 - // while(i<a.length){
96 - // let str=CurDay+' '+add+'의 '+a[i].fcstTime[0]+a[i].fcstTime[1]+'시 기온은 '+a[i].fcstValue+'이고, 강수확률은 '+a[i+1].fcstValue+'이다.';
97 - // result.push(str);
98 - // i+=2;
99 - //}//정보를 string으로 저장.
100 - while(i<a.length){
101 - let Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue};
102 - result.push(Json);
103 - i+=2;
104 - }//정보를 Json형식으로 저장.
105 - //return result를 해주고 싶은데 방법을 잘 모르겠음
106 - res.send(result);
107 - });//pop:강수확률 tmp:한시간 기온
108 }); 54 });
109 55
56 +let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
57 +//입력받기
58 +app.post('/api/weather',(req,res)=>{
59 + const nx = req.body.dotX;
60 + const ny = req.body.dotY;
61 +
62 + queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
63 + queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
64 + queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
65 + queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */
66 + queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */
67 + queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/
68 + queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/
110 69
111 -//시간대별 괜찮은 옷
112 -app.post('/clothes', (req, res) => {
113 request({ 70 request({
114 url: url + queryParams, 71 url: url + queryParams,
115 method: 'GET' 72 method: 'GET'
116 }, function (error, response, body) { 73 }, function (error, response, body) {
117 let ex=JSON.parse(body); 74 let ex=JSON.parse(body);
118 let item=ex.response.body.items.item; 75 let item=ex.response.body.items.item;
119 - // console.log(items); 76 +
120 let i=0; 77 let i=0;
121 - let a=[]; 78 + let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
122 while(item[i].fcstDate==CurDay){ 79 while(item[i].fcstDate==CurDay){
123 if(item[i].category=='POP' || item[i].category=='TMP'){ 80 if(item[i].category=='POP' || item[i].category=='TMP'){
124 a.push(item[i]); 81 a.push(item[i]);
...@@ -127,41 +84,13 @@ app.post('/clothes', (req, res) => { ...@@ -127,41 +84,13 @@ app.post('/clothes', (req, res) => {
127 } 84 }
128 let result=[]; 85 let result=[];
129 i=0; 86 i=0;
130 - let Json={};
131 while(i<a.length){ 87 while(i<a.length){
132 - let umb=0 88 + let Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue};
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); 89 result.push(Json);
161 i+=2; 90 i+=2;
162 } 91 }
163 - res.send(result); 92 + res.json(result);
164 - }); 93 + });//pop:강수확률 tmp:한시간 기온
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
......