Toggle navigation
Toggle navigation
This project
Loading...
Sign in
LI WENHAO
/
TFT
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
hellowhales
2021-11-29 18:15:36 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cf2448ddb69b02c1eb07e3c68b3ab3b25e8246f3
cf2448dd
1 parent
0d78d992
Divide public detail info
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
134 additions
and
39 deletions
APIhandler.js
server.js
APIhandler.js
View file @
cf2448d
let
request
=
require
(
'request'
);
let
options
=
{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList?ServiceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=
A
&numOfRows=12&pageNo=1&_type=json'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList?ServiceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=
C
&numOfRows=12&pageNo=1&_type=json'
,
'headers'
:
{
}
};
var
contentId
=
new
Array
();
request
(
options
,
function
(
error
,
response
,
body
)
{
if
(
error
)
{
throw
new
Error
(
error
);
throw
new
Error
(
error
);
}
let
info
=
JSON
.
parse
(
body
);
for
(
i
in
info
[
'response'
][
'body'
][
'items'
][
'item'
])
{
console
.
log
(
'축제 : '
+
info
[
'response'
][
'body'
][
'items'
][
'item'
][
i
][
'title'
]);
console
.
log
(
'축제 주소 : '
+
info
[
'response'
][
'body'
][
'items'
][
'item'
][
i
][
'addr1'
]);
console
.
log
(
'전화번호 : '
+
info
[
'response'
][
'body'
][
'items'
][
'item'
][
i
][
'tel'
]
);
console
.
log
(
'축제위도 : '
+
info
[
'response'
][
'body'
][
'items'
][
'item'
][
i
][
'mapx'
]);
console
.
log
(
'축제경도 : '
+
info
[
'response'
][
'body'
][
'items'
][
'item'
][
i
][
'mapy'
]);
console
.
log
(
" "
)
let
info
=
JSON
.
parse
(
body
);
for
(
i
in
info
[
'response'
][
'body'
][
'items'
][
'item'
]){
contentId
[
i
]
=
info
[
'response'
][
'body'
][
'items'
][
'item'
][
i
][
'contentid'
];
let
Info
=
{
'public'
:{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?ServiceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&contentTypeId=15&contentId='
+
contentId
[
i
]
+
'&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&defaultYN=Y&firstImageYN=Y&areacodeYN=Y&catcodeYN=Y&addrinfoYN=Y&mapinfoYN=Y&overviewYN=Y&transGuideYN=Y&_type=json'
,
'headers'
:
{}
},
'detail'
:{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?ServiceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&contentTypeId=15&contentId='
+
contentId
[
i
]
+
'&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&introYN=Y&_type=json'
,
'headers'
:
{}
},
'weather'
:
{
'method'
:
'GET'
,
'url'
:
'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst?serviceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&pageNo=1&numOfRows=50&dataType=JSON&base_date=20211129&base_time=0500&nx=55&ny=127'
,
'headers'
:
{}
}
};
request
(
Info
.
public
,
function
(
error
,
response
,
body
)
{
if
(
error
)
{
throw
new
Error
(
error
);
}
let
pinfo
=
JSON
.
parse
(
body
);
console
.
log
(
'축제 : '
+
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'title'
]);
console
.
log
(
'축제 주소 : '
+
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'addr1'
]);
console
.
log
(
'전화번호 : '
+
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'tel'
]);
console
.
log
(
'축제위도 : '
+
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'mapx'
]);
console
.
log
(
'축제경도 : '
+
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'mapy'
]);
console
.
log
(
'ID : '
+
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'contentid'
]);
console
.
log
(
'축제 정보 : '
+
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'overview'
]);
console
.
log
(
'이미지 Url : '
+
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'firstimage'
]);
console
.
log
(
'홈페이지 Url : '
+
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'homepage'
]);
console
.
log
(
''
)
});
request
(
Info
.
detail
,
function
(
error
,
response
,
body
)
{
if
(
error
)
{
throw
new
Error
(
error
);
}
let
dinfo
=
JSON
.
parse
(
body
);
console
.
log
(
'축제 시작일 : '
+
dinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'eventstartdate'
]);
console
.
log
(
'축제 종료일 : '
+
dinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'eventenddate'
]);
console
.
log
(
'나이제한 : '
+
dinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'agelimit'
]);
});
request
(
Info
.
weather
,
function
(
error
,
response
,
body
)
{
if
(
error
)
{
throw
new
Error
(
error
);
}
let
winfo
=
JSON
.
parse
(
body
);
for
(
let
item
of
winfo
[
'response'
][
'body'
][
'items'
][
'item'
])
{
if
(
item
[
'category'
]
==
'TMP'
)
{
console
.
log
(
'온도: '
+
item
[
'fcstValue'
]);
}
if
(
item
[
'category'
]
==
'PTY'
)
{
let
weather_code
=
item
[
'fcstValue'
]
if
(
weather_code
==
'1'
){
console
.
log
(
'날씨 : 비'
);}
else
if
(
weather_code
==
'2'
){
console
.
log
(
'날씨 :비/눈'
)
;}
else
if
(
weather_code
==
'3'
){
console
.
log
(
'날씨 :눈'
)
;}
else
if
(
weather_code
==
'4'
){
console
.
log
(
'날씨 :소나기'
)
;}
else
{
console
.
log
(
'없음'
)
;}
}
}
});
}
});
\ No newline at end of file
...
...
server.js
View file @
cf2448d
const
express
=
require
(
'express'
);
const
mongoose
=
require
(
'mongoose'
);
const
mongoose
=
require
(
'mongoose'
);
const
server
=
express
();
const
Festival
=
require
(
'./models/Festival'
);
const
Festival
=
require
(
'./models/Festival'
);
require
(
"dotenv"
).
config
({
path
:
"variables.env"
});
let
request
=
require
(
'request'
);
let
request
=
require
(
'request
-promise-native
'
);
let
options
=
{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList?ServiceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=
A
&numOfRows=12&pageNo=1&_type=json'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList?ServiceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=
C
&numOfRows=12&pageNo=1&_type=json'
,
'headers'
:
{
}
};
var
contentId
=
new
Array
();
request
(
options
,
function
(
error
,
response
,
body
)
{
if
(
error
)
{
throw
new
Error
(
error
);
}
let
info
=
JSON
.
parse
(
body
);
for
(
i
in
info
[
'response'
][
'body'
][
'items'
][
'item'
]){
contentId
[
i
]
=
info
[
'response'
][
'body'
][
'items'
][
'item'
][
7
][
'contentid'
];
let
Info
=
{
'public'
:{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?ServiceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&contentTypeId=15&contentId='
+
contentId
[
i
]
+
'&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&defaultYN=Y&firstImageYN=Y&areacodeYN=Y&catcodeYN=Y&addrinfoYN=Y&mapinfoYN=Y&overviewYN=Y&transGuideYN=Y&_type=json'
,
'headers'
:
{
}
},
'detail'
:{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?ServiceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&contentTypeId=15&contentId='
+
contentId
[
i
]
+
'&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&introYN=Y&_type=json'
,
'headers'
:
{
}
}
};
server
.
get
(
'/'
,(
req
,
res
)
=>
{
const
newFestival
=
new
Festival
();
newFestival
.
title
=
info
[
'response'
][
'body'
][
'items'
][
'item'
][
11
][
'title'
];
newFestival
.
addr
=
info
[
'response'
][
'body'
][
'items'
][
'item'
][
11
][
'addr1'
];
newFestival
.
tel
=
info
[
'response'
][
'body'
][
'items'
][
'item'
][
11
][
'tel'
];
newFestival
.
mapx
=
info
[
'response'
][
'body'
][
'items'
][
'item'
][
11
][
'mapx'
];
newFestival
.
mapy
=
info
[
'response'
][
'body'
][
'items'
][
'item'
][
11
][
'mapy'
];
newFestival
.
save
().
then
((
festival
)
=>
{
console
.
log
(
festival
);
res
.
json
({
message
:
'Festival Created Successfully'
});
})
.
catch
((
err
)
=>
{
res
.
json
({
message
:
'Festival was not successfully created'
request
(
Info
.
public
,
function
(
error
,
response
,
body
)
{
if
(
error
)
{
throw
new
Error
(
error
);
}
let
pinfo
=
JSON
.
parse
(
body
);
server
.
get
(
'/'
,
async
(
req
,
res
)
=>
{
const
newFestival
=
new
Festival
();
await
request
(
Info
.
detail
,
function
(
error
,
response
,
body
)
{
if
(
error
)
{
throw
new
Error
(
error
);
}
let
dinfo
=
JSON
.
parse
(
body
);
newFestival
.
eventstartdate
=
dinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'eventstartdate'
];
newFestival
.
eventenddate
=
dinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'eventenddate'
];
});
newFestival
.
title
=
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'title'
];
newFestival
.
addr
=
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'addr1'
];
newFestival
.
tel
=
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'tel'
];
newFestival
.
mapx
=
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'mapx'
];
newFestival
.
mapy
=
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'mapy'
];
newFestival
.
overview
=
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'overview'
];
newFestival
.
firstimage
=
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'firstimage'
];
newFestival
.
homepage
=
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'homepage'
];
newFestival
.
save
().
then
((
festival
)
=>
{
console
.
log
(
festival
,
"Save success!"
);
res
.
json
({
message
:
'Festival Created Successfully'
});
})
.
catch
((
err
)
=>
{
res
.
json
({
message
:
'Festival was not successfully created'
});
});
});
});
});
});
}
}
);
server
.
listen
(
3000
,(
err
)
=>
{
if
(
err
){
...
...
Please
register
or
login
to post a comment