Seokjin

[UPDATE]mainpage,address

This diff could not be displayed because it is too large.
...@@ -8,12 +8,16 @@ ...@@ -8,12 +8,16 @@
8 "@testing-library/user-event": "^13.5.0", 8 "@testing-library/user-event": "^13.5.0",
9 "cors": "^2.8.5", 9 "cors": "^2.8.5",
10 "express": "^4.18.1", 10 "express": "^4.18.1",
11 + "express-session": "^1.17.3",
11 "http-proxy-middleware": "^2.0.6", 12 "http-proxy-middleware": "^2.0.6",
13 + "mongoose": "^6.3.3",
12 "nodemon": "^2.0.16", 14 "nodemon": "^2.0.16",
13 "react": "^18.1.0", 15 "react": "^18.1.0",
14 "react-dom": "^18.1.0", 16 "react-dom": "^18.1.0",
15 "react-scripts": "5.0.1", 17 "react-scripts": "5.0.1",
16 - "web-vitals": "^2.1.4" 18 + "request": "^2.88.2",
19 + "web-vitals": "^2.1.4",
20 + "xlsx": "^0.18.5"
17 }, 21 },
18 "scripts": { 22 "scripts": {
19 "start": "react-scripts start", 23 "start": "react-scripts start",
......
1 var request = require('request'); 1 var request = require('request');
2 +let express = require('express');
3 +let app=express();
4 +let bodyParser = require('body-parser');
5 +let session = require('express-session')
6 +
7 +app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
8 +app.use(bodyParser.urlencoded({ extended: false }));
9 +app.use(bodyParser.json());
10 +//nx,ny구하기
11 +
12 +//변수들
13 +let curaddress;
14 +var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
15 +var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/
16 +
17 +
18 +
2 19
3 20
4 21
5 //nx,ny구하기 22 //nx,ny구하기
6 const xlsx=require('xlsx') 23 const xlsx=require('xlsx')
7 -const excel=xlsx.readFile('location(x,y).xlsx'); 24 +const excel=xlsx.readFile('location.xlsx');
8 const sheet=excel.SheetNames[0]; 25 const sheet=excel.SheetNames[0];
9 const first=excel.Sheets[sheet]; 26 const first=excel.Sheets[sheet];
10 const jsonData=xlsx.utils.sheet_to_json(first,{defval:""}); 27 const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
11 -let nx,ny; 28 +let nx,ny,add;
12 app.post('/address', (req, res) => { 29 app.post('/address', (req, res) => {
13 let i=0; 30 let i=0;
14 while(i<3788){ 31 while(i<3788){
15 - if(jsonData[i].address1==req.address1 && jsonData[i].address2==req.address2 && jsonData[i].address3==req.address3){ 32 + if(jsonData[i].address1==req.body.address1 && jsonData[i].address2==req.body.address2 && jsonData[i].address3==req.body.address3){
16 nx=jsonData[i].nx; 33 nx=jsonData[i].nx;
17 ny=jsonData[i].ny; 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;
18 break; 45 break;
19 } 46 }
20 i+=1; 47 i+=1;
21 } 48 }
22 - res.send("좌표는 ",nx,ny,"입니다.");
23 }); 49 });
24 50
25 51
26 -//jsonData.find() 여기서 server.js의 logid의 address123을 입력받아 이 것을 찾음 싶습니다. nx와 ny에 대입
27 -
28 -
29 -
30 -
31 -
32 -
33 -
34 //오늘의 날짜 구하기 52 //오늘의 날짜 구하기
35 let today=new Date(); 53 let today=new Date();
36 let CurDay=today.getFullYear().toString(); 54 let CurDay=today.getFullYear().toString();
...@@ -49,39 +67,50 @@ else{ ...@@ -49,39 +67,50 @@ else{
49 67
50 68
51 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=[];
52 //입력받기 76 //입력받기
53 -var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'; 77 +app.post('/mainpage',(req,res)=>{
54 -var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/ 78 + request({
55 -queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
56 -queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
57 -queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
58 -queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */
59 -queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */
60 -queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx.toString()); /*nx*/
61 -queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny.toString()); /*ny*/
62 -
63 -request({
64 url: url + queryParams, 79 url: url + queryParams,
65 method: 'GET' 80 method: 'GET'
66 -}, function (error, response, body) { 81 + }, function (error, response, body) {
67 - // console.log('Status', response.statusCode); 82 + let ex=JSON.parse(body);
68 - // console.log('Headers', JSON.stringify(response.headers)); 83 + let item=ex.response.body.items.item;
69 - // console.log('Reponse received', body); 84 + // console.log(items);
70 - let temp=JSON.parse(body); 85 + let i=0;
71 - // let tmp=temp.map((list)=> ({ 86 + let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
72 - // fcstTime:list.fcstTime, 87 + while(item[i].fcstDate==CurDay){
73 - // category:list.category, 88 + if(item[i].category=='POP' || item[i].category=='TMP'){
74 - // fcstValue:list.fcstValue 89 + a.push(item[i]);
75 - // })) ; 90 + }
76 - let temp2=temp.response.body.items.item.map((list)=>({ 91 + i+=1;
77 - baseDate:list.baseDate, 92 + }
78 - category:list.category, 93 + let result=[];
79 - fcstDate:list.fcstDate, 94 + i=0;
80 - fcstTime:list.fcstTime, 95 + while(i<a.length){
81 - fcstValue:list.fcstValue 96 + let str=CurDay+' '+add+'의 '+a[i].fcstTime[0]+a[i].fcstTime[1]+'시 기온은 '+a[i].fcstValue+'이고, 강수확률은 '+a[i+1].fcstValue+'이다.';
82 - })); 97 + result.push(str);
83 - console.log(temp2); 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].baseTime.fcstValue};
102 + // result.push(Json);
103 + // i+=2;
104 + // }//정보를 Json형식으로 저장.
105 + //return result를 해주고 싶은데 방법을 잘 모르겠음
106 + res.send(result);
107 + });//pop:강수확률 tmp:한시간 기온
84 }); 108 });
85 -app.post('/mainpage', (req, res) => {
86 109
87 -});
...\ No newline at end of file ...\ No newline at end of file
110 +
111 +
112 +// app.post('/mainpage', (req, res) => {
113 +
114 +// });
115 +
116 +app.listen(4000, () => console.log('Server On 5000'));
...\ No newline at end of file ...\ No newline at end of file
......