Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김건희
/
OSSW_Weather_Briefing
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김건희
2022-06-01 12:54:24 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
450cc6599a7e3f104d7b2cb7791e44d6fb4e9c9c
450cc659
2 parents
d4b03008
ed438325
[Merge] 'feature/weather' into 'backend'
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
88 deletions
weather_briefing/package-lock.json
weather_briefing/package.json
weather_briefing/server/weather.js
weather_briefing/package-lock.json
View file @
450cc65
...
...
@@ -3667,9 +3667,9 @@
}
},
"bson"
:
{
"version"
:
"4.6.
4
"
,
"resolved"
:
"https://registry.npmjs.org/bson/-/bson-4.6.
4
.tgz"
,
"integrity"
:
"sha512-
TdQ3FzguAu5HKPPlr0kYQCyrYUYh8tFM+CMTpxjNzVzxeiJY00Rtuj3LXLHSgiGvmaWlZ8PE+4KyM2thqE38pQ
=="
,
"version"
:
"4.6.
3
"
,
"resolved"
:
"https://registry.npmjs.org/bson/-/bson-4.6.
3
.tgz"
,
"integrity"
:
"sha512-
rAqP5hcUVJhXP2MCSNVsf0oM2OGU1So6A9pVRDYayvJ5+hygXHQApf87wd5NlhPM1J9RJnbqxIG/f8QTzRoQ4A
=="
,
"requires"
:
{
"buffer"
:
"^5.6.0"
}
...
...
@@ -8849,15 +8849,15 @@
}
},
"mongoose"
:
{
"version"
:
"6.3.
4
"
,
"resolved"
:
"https://registry.npmjs.org/mongoose/-/mongoose-6.3.
4
.tgz"
,
"integrity"
:
"sha512-
UP0azyGMdY+2YNbJUHeHhnVw5vPzCqs4GQDUwHkilif/rwmSZktUQhQWMp1pUgRNeF2JC30vWGLrInZxD7K/Q
w=="
,
"version"
:
"6.3.
3
"
,
"resolved"
:
"https://registry.npmjs.org/mongoose/-/mongoose-6.3.
3
.tgz"
,
"integrity"
:
"sha512-
bAGuf+6mXuVjKReNcOGjdI05y9g0JXnRpZ3/PBN3kVXIn3rbhbFwR/lPbuwtsBsWhlblMK8tieDeFAVzV6yhw
w=="
,
"requires"
:
{
"bson"
:
"^4.6.2"
,
"kareem"
:
"2.3.5"
,
"mongodb"
:
"4.5.0"
,
"mpath"
:
"0.9.0"
,
"mquery"
:
"4.0.
3
"
,
"mquery"
:
"4.0.
2
"
,
"ms"
:
"2.1.3"
,
"sift"
:
"16.0.0"
},
...
...
@@ -8875,9 +8875,9 @@
"integrity"
:
"sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew=="
},
"mquery"
:
{
"version"
:
"4.0.
3
"
,
"resolved"
:
"https://registry.npmjs.org/mquery/-/mquery-4.0.
3
.tgz"
,
"integrity"
:
"sha512-
J5heI+P08I6VJ2Ky3+33IpCdAvlYGTSUjwTPxkAr8i8EoduPMBX2OY/wa3IKZIQl7MU4SbFk8ndgSKyB/cl1z
A=="
,
"version"
:
"4.0.
2
"
,
"resolved"
:
"https://registry.npmjs.org/mquery/-/mquery-4.0.
2
.tgz"
,
"integrity"
:
"sha512-
oAVF0Nil1mT3rxty6Zln4YiD6x6QsUWYz927jZzjMxOK2aqmhEz5JQ7xmrKK7xRFA2dwV+YaOpKU/S+vfNqKx
A=="
,
"requires"
:
{
"debug"
:
"4.x"
}
...
...
weather_briefing/package.json
View file @
450cc65
...
...
@@ -10,7 +10,7 @@
"express"
:
"^4.18.1"
,
"express-session"
:
"^1.17.3"
,
"http-proxy-middleware"
:
"^2.0.6"
,
"mongoose"
:
"^6.3.
4
"
,
"mongoose"
:
"^6.3.
3
"
,
"nodemon"
:
"^2.0.16"
,
"react"
:
"^18.1.0"
,
"react-dom"
:
"^18.1.0"
,
...
...
weather_briefing/server/weather.js
View file @
450cc65
...
...
@@ -2,11 +2,13 @@ var request = require('request');
let
express
=
require
(
'express'
);
let
app
=
express
();
let
bodyParser
=
require
(
'body-parser'
);
let
session
=
require
(
'express-session'
)
let
session
=
require
(
'express-session'
);
let
cors
=
require
(
'cors'
);
app
.
use
(
session
({
secret
:
'keyboard cat'
,
cookie
:
{
maxAge
:
60000
}}))
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
bodyParser
.
json
());
app
.
use
(
cors
());
//nx,ny구하기
//변수들
...
...
@@ -14,10 +16,21 @@ let curaddress;
var
url
=
'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'
;
var
queryParams
=
'?'
+
encodeURIComponent
(
'serviceKey'
)
+
'=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'
;
/* Service Key*/
//오늘의 날짜 구하기
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
();
}
//nx,ny구하기
const
xlsx
=
require
(
'xlsx'
)
...
...
@@ -25,92 +38,59 @@ const excel=xlsx.readFile('location.xlsx');
const
sheet
=
excel
.
SheetNames
[
0
];
const
first
=
excel
.
Sheets
[
sheet
];
const
jsonData
=
xlsx
.
utils
.
sheet_to_json
(
first
,{
defval
:
""
});
let
nx
,
ny
,
add
;
app
.
post
(
'/address'
,
(
req
,
res
)
=>
{
let
nx
,
ny
;
app
.
post
(
'/a
pi/a
ddress'
,
(
req
,
res
)
=>
{
let
i
=
0
;
while
(
i
<
3788
){
if
(
jsonData
[
i
].
address1
==
req
.
body
.
address1
&&
jsonData
[
i
].
address2
==
req
.
body
.
address2
&&
jsonData
[
i
].
address3
==
req
.
body
.
address3
){
nx
=
jsonData
[
i
].
nx
;
ny
=
jsonData
[
i
].
ny
;
curaddress
=
jsonData
[
i
];
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
);
/*nx*/
queryParams
+=
'&'
+
encodeURIComponent
(
'ny'
)
+
'='
+
encodeURIComponent
(
ny
);
/*ny*/
res
.
send
(
"좌표는 "
+
nx
+
" "
+
ny
+
"입니다."
);
add
=
req
.
body
.
address1
+
' '
+
req
.
body
.
address2
+
' '
+
req
.
body
.
address3
;
res
.
json
({
nx
,
ny
});
break
;
}
i
+=
1
;
}
});
//오늘의 날짜 구하기
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
();
}
let
a3
=
[],
a4
=
[],
a5
=
[],
a6
=
[],
a7
=
[],
a8
=
[],
a9
=
[],
a10
=
[],
a11
=
[],
a12
=
[],
a13
=
[],
a14
=
[],
a15
=
[],
a16
=
[],
a17
=
[],
a18
=
[],
a19
=
[],
a20
=
[],
a21
=
[],
a22
=
[],
a23
=
[];
//입력받기
app
.
post
(
'/mainpage'
,(
req
,
res
)
=>
{
request
({
url
:
url
+
queryParams
,
method
:
'GET'
},
function
(
error
,
response
,
body
)
{
let
ex
=
JSON
.
parse
(
body
);
let
item
=
ex
.
response
.
body
.
items
.
item
;
// console.log(items);
let
i
=
0
;
let
a
=
[];
//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
while
(
item
[
i
].
fcstDate
==
CurDay
){
if
(
item
[
i
].
category
==
'POP'
||
item
[
i
].
category
==
'TMP'
){
a
.
push
(
item
[
i
]);
}
i
+=
1
;
}
let
result
=
[];
i
=
0
;
while
(
i
<
a
.
length
){
let
str
=
CurDay
+
' '
+
add
+
'의 '
+
a
[
i
].
fcstTime
[
0
]
+
a
[
i
].
fcstTime
[
1
]
+
'시 기온은 '
+
a
[
i
].
fcstValue
+
'이고, 강수확률은 '
+
a
[
i
+
1
].
fcstValue
+
'이다.'
;
result
.
push
(
str
);
i
+=
2
;
}
//정보를 string으로 저장.
// while(i<a.length){
// let Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].baseTime.fcstValue};
// result.push(Json);
// i+=2;
// }//정보를 Json형식으로 저장.
//return result를 해주고 싶은데 방법을 잘 모르겠음
res
.
send
(
result
);
});
//pop:강수확률 tmp:한시간 기온
app
.
post
(
'/api/weather'
,(
req
,
res
)
=>
{
const
nx
=
req
.
body
.
dotX
;
const
ny
=
req
.
body
.
dotY
;
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
);
/*nx*/
queryParams
+=
'&'
+
encodeURIComponent
(
'ny'
)
+
'='
+
encodeURIComponent
(
ny
);
/*ny*/
request
({
url
:
url
+
queryParams
,
method
:
'GET'
},
function
(
error
,
response
,
body
)
{
let
ex
=
JSON
.
parse
(
body
);
let
item
=
ex
.
response
.
body
.
items
.
item
;
let
i
=
0
;
let
a
=
[];
//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
while
(
item
[
i
].
fcstDate
==
CurDay
){
if
(
item
[
i
].
category
==
'POP'
||
item
[
i
].
category
==
'TMP'
){
a
.
push
(
item
[
i
]);
}
i
+=
1
;
}
let
result
=
[];
i
=
0
;
while
(
i
<
a
.
length
){
let
Json
=
{
today
:
CurDay
,
time
:
a
[
i
].
fcstTime
[
0
]
+
a
[
i
].
fcstTime
[
1
],
temperature
:
a
[
i
].
fcstValue
,
rainPer
:
a
[
i
+
1
].
fcstValue
};
result
.
push
(
Json
);
i
+=
2
;
}
res
.
json
(
result
);
});
//pop:강수확률 tmp:한시간 기온
});
// app.post('/mainpage', (req, res) => {
// });
app
.
listen
(
4000
,
()
=>
console
.
log
(
'Server On 5000'
));
\ No newline at end of file
...
...
Please
register
or
login
to post a comment