Showing
3 changed files
with
49 additions
and
69 deletions
... | @@ -3667,9 +3667,9 @@ | ... | @@ -3667,9 +3667,9 @@ |
3667 | } | 3667 | } |
3668 | }, | 3668 | }, |
3669 | "bson": { | 3669 | "bson": { |
3670 | - "version": "4.6.4", | 3670 | + "version": "4.6.3", |
3671 | - "resolved": "https://registry.npmjs.org/bson/-/bson-4.6.4.tgz", | 3671 | + "resolved": "https://registry.npmjs.org/bson/-/bson-4.6.3.tgz", |
3672 | - "integrity": "sha512-TdQ3FzguAu5HKPPlr0kYQCyrYUYh8tFM+CMTpxjNzVzxeiJY00Rtuj3LXLHSgiGvmaWlZ8PE+4KyM2thqE38pQ==", | 3672 | + "integrity": "sha512-rAqP5hcUVJhXP2MCSNVsf0oM2OGU1So6A9pVRDYayvJ5+hygXHQApf87wd5NlhPM1J9RJnbqxIG/f8QTzRoQ4A==", |
3673 | "requires": { | 3673 | "requires": { |
3674 | "buffer": "^5.6.0" | 3674 | "buffer": "^5.6.0" |
3675 | } | 3675 | } |
... | @@ -8849,15 +8849,15 @@ | ... | @@ -8849,15 +8849,15 @@ |
8849 | } | 8849 | } |
8850 | }, | 8850 | }, |
8851 | "mongoose": { | 8851 | "mongoose": { |
8852 | - "version": "6.3.4", | 8852 | + "version": "6.3.3", |
8853 | - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.3.4.tgz", | 8853 | + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.3.3.tgz", |
8854 | - "integrity": "sha512-UP0azyGMdY+2YNbJUHeHhnVw5vPzCqs4GQDUwHkilif/rwmSZktUQhQWMp1pUgRNeF2JC30vWGLrInZxD7K/Qw==", | 8854 | + "integrity": "sha512-bAGuf+6mXuVjKReNcOGjdI05y9g0JXnRpZ3/PBN3kVXIn3rbhbFwR/lPbuwtsBsWhlblMK8tieDeFAVzV6yhww==", |
8855 | "requires": { | 8855 | "requires": { |
8856 | "bson": "^4.6.2", | 8856 | "bson": "^4.6.2", |
8857 | "kareem": "2.3.5", | 8857 | "kareem": "2.3.5", |
8858 | "mongodb": "4.5.0", | 8858 | "mongodb": "4.5.0", |
8859 | "mpath": "0.9.0", | 8859 | "mpath": "0.9.0", |
8860 | - "mquery": "4.0.3", | 8860 | + "mquery": "4.0.2", |
8861 | "ms": "2.1.3", | 8861 | "ms": "2.1.3", |
8862 | "sift": "16.0.0" | 8862 | "sift": "16.0.0" |
8863 | }, | 8863 | }, |
... | @@ -8875,9 +8875,9 @@ | ... | @@ -8875,9 +8875,9 @@ |
8875 | "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==" | 8875 | "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==" |
8876 | }, | 8876 | }, |
8877 | "mquery": { | 8877 | "mquery": { |
8878 | - "version": "4.0.3", | 8878 | + "version": "4.0.2", |
8879 | - "resolved": "https://registry.npmjs.org/mquery/-/mquery-4.0.3.tgz", | 8879 | + "resolved": "https://registry.npmjs.org/mquery/-/mquery-4.0.2.tgz", |
8880 | - "integrity": "sha512-J5heI+P08I6VJ2Ky3+33IpCdAvlYGTSUjwTPxkAr8i8EoduPMBX2OY/wa3IKZIQl7MU4SbFk8ndgSKyB/cl1zA==", | 8880 | + "integrity": "sha512-oAVF0Nil1mT3rxty6Zln4YiD6x6QsUWYz927jZzjMxOK2aqmhEz5JQ7xmrKK7xRFA2dwV+YaOpKU/S+vfNqKxA==", |
8881 | "requires": { | 8881 | "requires": { |
8882 | "debug": "4.x" | 8882 | "debug": "4.x" |
8883 | } | 8883 | } | ... | ... |
... | @@ -10,7 +10,7 @@ | ... | @@ -10,7 +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 | - "mongoose": "^6.3.4", | 13 | + "mongoose": "^6.3.3", |
14 | "nodemon": "^2.0.16", | 14 | "nodemon": "^2.0.16", |
15 | "react": "^18.1.0", | 15 | "react": "^18.1.0", |
16 | "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,63 +38,42 @@ const excel=xlsx.readFile('location.xlsx'); | ... | @@ -25,63 +38,42 @@ 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)=>{ |
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*/ | ||
69 | + | ||
78 | request({ | 70 | request({ |
79 | url: url + queryParams, | 71 | url: url + queryParams, |
80 | method: 'GET' | 72 | method: 'GET' |
81 | }, function (error, response, body) { | 73 | }, function (error, response, body) { |
82 | let ex=JSON.parse(body); | 74 | let ex=JSON.parse(body); |
83 | let item=ex.response.body.items.item; | 75 | let item=ex.response.body.items.item; |
84 | - // console.log(items); | 76 | + |
85 | let i=0; | 77 | 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=[]; | 78 | let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; |
87 | while(item[i].fcstDate==CurDay){ | 79 | while(item[i].fcstDate==CurDay){ |
... | @@ -93,24 +85,12 @@ app.post('/mainpage',(req,res)=>{ | ... | @@ -93,24 +85,12 @@ app.post('/mainpage',(req,res)=>{ |
93 | let result=[]; | 85 | let result=[]; |
94 | i=0; | 86 | i=0; |
95 | while(i<a.length){ | 87 | while(i<a.length){ |
96 | - let str=CurDay+' '+add+'의 '+a[i].fcstTime[0]+a[i].fcstTime[1]+'시 기온은 '+a[i].fcstValue+'이고, 강수확률은 '+a[i+1].fcstValue+'이다.'; | 88 | + let Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue}; |
97 | - result.push(str); | 89 | + result.push(Json); |
98 | i+=2; | 90 | i+=2; |
99 | - }//정보를 string으로 저장. | 91 | + } |
100 | - // while(i<a.length){ | 92 | + res.json(result); |
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:한시간 기온 | 93 | });//pop:강수확률 tmp:한시간 기온 |
108 | }); | 94 | }); |
109 | 95 | ||
110 | - | ||
111 | - | ||
112 | -// app.post('/mainpage', (req, res) => { | ||
113 | - | ||
114 | -// }); | ||
115 | - | ||
116 | app.listen(4000, () => console.log('Server On 5000')); | 96 | app.listen(4000, () => console.log('Server On 5000')); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment