weather.js
2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var request = require('request');
//nx,ny구하기
const xlsx=require('xlsx')
const excel=xlsx.readFile('location(x,y).xlsx');
const sheet=excel.SheetNames[0];
const first=excel.Sheets[sheet];
const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
let nx,ny;
app.post('/address', (req, res) => {
let i=0;
while(i<3788){
if(jsonData[i].address1==req.address1 && jsonData[i].address2==req.address2 && jsonData[i].address3==req.address3){
nx=jsonData[i].nx;
ny=jsonData[i].ny;
break;
}
i+=1;
}
res.send("좌표는 ",nx,ny,"입니다.");
});
//jsonData.find() 여기서 server.js의 logid의 address123을 입력받아 이 것을 찾음 싶습니다. nx와 ny에 대입
//오늘의 날짜 구하기
let today=new Date();
let CurDay=today.getFullYear().toString();
if(today.getMonth()<9){
CurDay+="0"+(today.getMonth()+1).toString();
}
else{
CurDay+=(today.getMonth()+1).toString();
}
if(today.getDate()<10){
CurDay+="0"+today.getDate().toString();
}
else{
CurDay+=today.getDate().toString();
}
//입력받기
var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */
queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */
queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx.toString()); /*nx*/
queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny.toString()); /*ny*/
request({
url: url + queryParams,
method: 'GET'
}, function (error, response, body) {
// console.log('Status', response.statusCode);
// console.log('Headers', JSON.stringify(response.headers));
// console.log('Reponse received', body);
let temp=JSON.parse(body);
// let tmp=temp.map((list)=> ({
// fcstTime:list.fcstTime,
// category:list.category,
// fcstValue:list.fcstValue
// })) ;
let temp2=temp.response.body.items.item.map((list)=>({
baseDate:list.baseDate,
category:list.category,
fcstDate:list.fcstDate,
fcstTime:list.fcstTime,
fcstValue:list.fcstValue
}));
console.log(temp2);
});
app.post('/mainpage', (req, res) => {
});