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-30 21:23:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ee6e1631e60e4959a45c6c9ee83f86dcb57959be
ee6e1631
1 parent
abbd2925
Simplify ApiHandler
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
309 deletions
APIhandler.js
festivalList.json
models/Festival.js
server.js
APIhandler.js
deleted
100644 → 0
View file @
abbd292
let
request
=
require
(
'request'
);
let
options
=
{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList?ServiceKey=3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%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'
][
i
][
'contentid'
];
let
Info
=
{
'public'
:
{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?'
+
'ServiceKey='
+
'3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%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='
+
'3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%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='
+
'3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%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'
]);
}
else
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
(
'없음'
)
;}
}
}
});
}
});
festivalList.json
deleted
100644 → 0
View file @
abbd292
{
"_id"
:
{
"$oid"
:
"619a35f2a96f26c4d20a5122"
},
"title"
:
"《MMCA 이건희컬렉션 특별전: 한국미술명작》"
,
"addr"
:
"서울특별시 종로구 삼청로 30"
,
"tel"
:
"02-3701-9500"
,
"mapx"
:
126.9800649747
,
"mapy"
:
37.5788361778
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:05:06.042Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:05:06.042Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a361f6a4cad598e278632"
},
"title"
:
"가무악극으로 만나는 토요 상설공연"
,
"addr"
:
"충청남도 부여군 규암면 백제문로 388"
,
"tel"
:
"041-832-5765"
,
"mapx"
:
126.8997016069
,
"mapy"
:
36.3048428766
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:05:51.663Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:05:51.663Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a3642f8e65868598b5a17"
},
"title"
:
"가산수피아 '봄의 정원'"
,
"addr"
:
"경상북도 칠곡군 가산면 학하들안2길 105"
,
"tel"
:
"054-971-9861"
,
"mapx"
:
128.4850691574
,
"mapy"
:
36.0861545517
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:06:26.416Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:06:26.416Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a3663a1816be4d2a4882b"
},
"title"
:
"가족끼리 빙어체험 2021"
,
"addr"
:
"경기도 양평군 단월면 곱다니길 55-2 수미마을 방문객센터"
,
"tel"
:
"031-775-5205"
,
"mapx"
:
127.6574135888
,
"mapy"
:
37.514550408
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:06:59.535Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:06:59.535Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a3688b715b78b16cc6208"
},
"title"
:
"가족끼리딸기 캠피닉"
,
"addr"
:
"경기도 양평군 단월면 곱다니길 55-2"
,
"tel"
:
"031-775-5205"
,
"mapx"
:
127.657366373
,
"mapy"
:
37.5144948588
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:07:36.556Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:07:36.556Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a36abc8bcb135bf91ff48"
},
"title"
:
"가족오페라 <마술피리> 2021"
,
"addr"
:
"대구광역시 북구 호암로 15"
,
"tel"
:
"053-666-6170"
,
"mapx"
:
128.592257023
,
"mapy"
:
35.8835072863
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:08:11.131Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:08:11.131Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a36d2623874f5ebdb540d"
},
"title"
:
"감악산 꽃&별 여행"
,
"addr"
:
"거창군 신원면 덕산리 산 57"
,
"tel"
:
"055-940-3390"
,
"mapx"
:
127.9163995903
,
"mapy"
:
35.5912836573
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:08:50.766Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:08:50.766Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a36ff8d2678a5079637ab"
},
"title"
:
"강동북페스티벌"
,
"addr"
:
"온라인 개최"
,
"tel"
:
"강일 427-4004, 성내 471-0044, 해공 478-9656, 암사 429-0476, 천호 488-7223, 둔촌 489-6557"
,
"mapx"
:
127.1573829418
,
"mapy"
:
37.5512675743
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:09:35.075Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:09:35.075Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a37162e9742f8315195ed"
},
"title"
:
"강동선사문화축제"
,
"addr"
:
"서울특별시 강동구 성내로 25"
,
"tel"
:
"02-3425-8530"
,
"mapx"
:
127.1237865998
,
"mapy"
:
37.530177751
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:09:58.635Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:09:58.635Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a3733fc3082f196a0a589"
},
"title"
:
"강동청년축제"
,
"tel"
:
"02-482-7647"
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:10:27.165Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:10:27.165Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a379163ec5352d3c1bae6"
},
"title"
:
"강릉 단오제"
,
"addr"
:
"강원도 강릉시 단오장길 1"
,
"tel"
:
"033-641-1593"
,
"mapx"
:
128.8950169869
,
"mapy"
:
37.7482134974
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:12:01.456Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:12:01.456Z"
},
"__v"
:
0
}
{
"_id"
:
{
"$oid"
:
"619a37aba63f1a25f61a4f5e"
},
"title"
:
"강릉국제영화제(GIFF)"
,
"addr"
:
"강원도 강릉시 경강로2021번길 9-1"
,
"tel"
:
"033-641-8079"
,
"mapx"
:
128.8898396064
,
"mapy"
:
37.7504353618
,
"createdAt"
:
{
"$date"
:
"2021-11-21T12:12:27.604Z"
},
"updatedAt"
:
{
"$date"
:
"2021-11-21T12:12:27.604Z"
},
"__v"
:
0
}
\ No newline at end of file
models/Festival.js
View file @
ee6e163
...
...
@@ -12,8 +12,6 @@ const festivalSchema = new Schema({
overview
:
String
,
firstimage
:
String
,
homepage
:
String
,
district
:
String
,
city
:
String
,
temparature
:
Number
,
weathers
:
String
// weather : {
...
...
server.js
View file @
ee6e163
...
...
@@ -4,7 +4,10 @@ const db = require('mongodb');
const
Festival
=
require
(
'./models/Festival'
);
const
request
=
require
(
'request-promise-native'
);
require
(
"dotenv"
).
config
({
path
:
"variables.env"
});
const
ServiceKey
=
'3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D'
;
const
ServiceKey2
=
'%2FGjtI8kwZeJTzJm%2BxUxz%2Bjh15wnmV3rwFuRvrq3oRSqyklfiZfbUaqmsG0McVPJMdXSUYetGaCXl0ZkbfMI0BQ%3D%3D'
const
ServiceKey3
=
'%2FsBWti235XX%2Fg1%2FqBZfiNQ6A%2BJmF3WL%2FboaNqJH4v3eWic59SiHc6W5vgZKU7Hjocj%2BAntIqHfhXOpmE5CpAFw%3D%3D'
const
WeatherServiceKey
=
'2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D'
;
const
COORDINATES
=
require
(
'./coordinates'
)[
'COORDINATES'
];
const
DISTRICT
=
[
"서울특별시"
,
"부산광역시"
,
"울산광역시"
,
"대구광역시"
,
"대전광역시"
,
...
...
@@ -51,7 +54,7 @@ mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{
let
options
=
{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList'
+
'?ServiceKey='
+
'3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D'
+
'?ServiceKey='
+
ServiceKey2
+
'&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=C&numOfRows=12'
+
'&pageNo='
+
i
+
'&_type=json'
,
...
...
@@ -64,13 +67,14 @@ mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{
throw
new
Error
(
error
);
}
let
info
=
JSON
.
parse
(
body
);
let
items
=
info
[
'response'
][
'body'
][
'items'
][
'item'
];
for
(
item
of
items
)
{
let
Info
=
{
'public'
:
{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?'
+
'ServiceKey='
+
'3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D'
+
'ServiceKey='
+
ServiceKey2
+
'&contentTypeId='
+
'15'
+
'&contentId='
+
item
[
'contentid'
]
+
'&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&defaultYN=Y&firstImageYN=Y&areacodeYN=Y&catcodeYN=Y&addrinfoYN=Y&mapinfoYN=Y&overviewYN=Y&transGuideYN=Y&_type=json'
,
...
...
@@ -79,7 +83,7 @@ mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{
'detail'
:
{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?'
+
'ServiceKey='
+
'3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D'
+
'ServiceKey='
+
ServiceKey2
+
'&contentTypeId='
+
'15'
+
'&contentId='
+
item
[
'contentid'
]
+
'&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&introYN=Y&_type=json'
,
...
...
@@ -110,8 +114,7 @@ mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{
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
.
district
=
distriction
[
0
];
// 광역시/도
newFestival
.
city
=
distriction
[
1
];
// 시군구
await
request
(
Info
.
detail
,
function
(
error
,
response
,
body
)
{
if
(
error
)
{
...
...
@@ -128,11 +131,11 @@ mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{
let
curDate
=
(
'0500'
<
todayTime
?
todayString
:
yesterdayString
);
Info
.
weather
.
url
=
'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst?'
+
'serviceKey='
+
'2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D'
+
'serviceKey='
+
WeatherServiceKey
+
'&pageNo='
+
'1'
+
'&numOfRows='
+
'2000'
+
'&dataType='
+
'JSON'
+
'&base_date='
+
'20211129'
+
'&base_date='
+
curDate
+
'&base_time='
+
'0500'
+
'&nx='
+
nx
+
'&ny='
+
ny
;
...
...
Please
register
or
login
to post a comment