Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박정민
/
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 20:40:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
39dae057d1a174e5f015ac25eadb9842ed91d51e
39dae057
1 parent
cf2448dd
Add weather info
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
654 additions
and
109 deletions
APIhandler.js
coordinates.js
festivalList.json
server.js
APIhandler.js
View file @
39dae05
...
...
@@ -5,6 +5,7 @@ let options = {
'headers'
:
{
}
};
var
contentId
=
new
Array
();
request
(
options
,
function
(
error
,
response
,
body
)
{
if
(
error
)
{
...
...
@@ -14,20 +15,35 @@ 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'
:
{}
'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'
:
{}
'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'
:
{
'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'
,
'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'
:
{}
}
};
...
...
@@ -56,30 +72,26 @@ for(i in info['response']['body']['items']['item']){
console
.
log
(
'축제 종료일 : '
+
dinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'eventenddate'
]);
console
.
log
(
'나이제한 : '
+
dinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'agelimit'
]);
});
request
(
Info
.
weather
,
function
(
error
,
response
,
body
)
{
request
(
Info
.
weather
,
function
(
error
,
response
,
body
)
{
if
(
error
)
{
throw
new
Error
(
error
);
throw
new
Error
(
error
);
}
let
winfo
=
JSON
.
parse
(
body
);
for
(
let
item
of
winfo
[
'response'
][
'body'
][
'items'
][
'item'
])
{
let
winfo
=
JSON
.
parse
(
body
);
if
(
item
[
'category'
]
==
'TMP'
)
{
console
.
log
(
'온도: '
+
item
[
'fcstValue'
]);
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
(
'없음'
)
;}
}
}
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
(
'없음'
)
;}
}
}
});
});
}
});
...
...
coordinates.js
0 → 100644
View file @
39dae05
exports
.
COORDINATES
=
{
"서울특별시"
:
{
"종로구"
:
[
60
,
127
],
"중구"
:
[
60
,
127
],
"용산구"
:
[
60
,
126
],
"성동구"
:
[
61
,
127
],
"광진구"
:
[
62
,
126
],
"동대문구"
:
[
61
,
127
],
"중랑구"
:
[
62
,
128
],
"성북구"
:
[
61
,
127
],
"강북구"
:
[
61
,
128
],
"도봉구"
:
[
61
,
129
],
"노원구"
:
[
61
,
129
],
"은평구"
:
[
59
,
127
],
"서대문구"
:
[
59
,
127
],
"마포구"
:
[
59
,
127
],
"양천구"
:
[
58
,
126
],
"강서구"
:
[
58
,
126
],
"구로구"
:
[
58
,
125
],
"금천구"
:
[
59
,
124
],
"영등포구"
:
[
58
,
126
],
"동작구"
:
[
59
,
125
],
"관악구"
:
[
59
,
125
],
"서초구"
:
[
61
,
125
],
"강남구"
:
[
61
,
126
],
"송파구"
:
[
62
,
126
],
"강동구"
:
[
62
,
126
]
},
"부산광역시"
:
{
"중구"
:
[
97
,
74
],
"서구"
:
[
97
,
74
],
"동구"
:
[
98
,
75
],
"영도구"
:
[
98
,
74
],
"부산진구"
:
[
97
,
75
],
"동래구"
:
[
98
,
76
],
"남구"
:
[
98
,
75
],
"북구"
:
[
96
,
76
],
"해운대구"
:
[
99
,
75
],
"사하구"
:
[
96
,
74
],
"금정구"
:
[
98
,
77
],
"강서구"
:
[
96
,
76
],
"연제구"
:
[
98
,
76
],
"수영구"
:
[
99
,
75
],
"사상구"
:
[
96
,
75
],
"기장군"
:
[
100
,
77
]
},
"대구광역시"
:
{
"중구"
:
[
89
,
90
],
"동구"
:
[
90
,
91
],
"서구"
:
[
88
,
90
],
"남구"
:
[
89
,
90
],
"북구"
:
[
89
,
91
],
"수성구"
:
[
89
,
90
],
"달서구"
:
[
88
,
90
],
"달성군"
:
[
86
,
88
]
},
"인천광역시"
:
{
"중구"
:
[
54
,
125
],
"동구"
:
[
54
,
125
],
"미추홀구"
:
[
54
,
124
],
"연수구"
:
[
55
,
123
],
"남동구"
:
[
56
,
124
],
"부평구"
:
[
55
,
125
],
"계양구"
:
[
56
,
126
],
"서구"
:
[
55
,
126
],
"강화군"
:
[
51
,
130
],
"옹진군"
:
[
54
,
124
]
},
"광주광역시"
:
{
"동구"
:
[
60
,
74
],
"서구"
:
[
59
,
74
],
"남구"
:
[
59
,
73
],
"북구"
:
[
59
,
75
],
"광산구"
:
[
57
,
74
]
},
"대전광역시"
:
{
"동구"
:
[
68
,
100
],
"중구"
:
[
68
,
100
],
"서구"
:
[
67
,
100
],
"유성구"
:
[
67
,
101
],
"대덕구"
:
[
68
,
100
]
},
"울산광역시"
:
{
"중구"
:
[
102
,
84
],
"남구"
:
[
102
,
84
],
"동구"
:
[
104
,
83
],
"북구"
:
[
103
,
85
],
"울주군"
:
[
101
,
84
]
},
"세종특별자치시"
:
{
"세종특별자치시"
:
[
66
,
103
]
},
"경기도"
:
{
"수원시"
:
[
61
,
120
],
"성남시"
:
[
63
,
124
],
"의정부시"
:
[
61
,
130
],
"안양시"
:
[
59
,
123
],
"부천시"
:
[
56
,
125
],
"광명시"
:
[
58
,
125
],
"평택시"
:
[
62
,
114
],
"동두천시"
:
[
61
,
134
],
"안산시"
:
[
58
,
121
],
"고양시"
:
[
57
,
128
],
"과천시"
:
[
60
,
124
],
"구리시"
:
[
62
,
127
],
"남양주시"
:
[
64
,
128
],
"오산시"
:
[
62
,
118
],
"시흥시"
:
[
57
,
123
],
"군포시"
:
[
59
,
122
],
"의왕시"
:
[
60
,
122
],
"하남시"
:
[
64
,
126
],
"용인시"
:
[
64
,
119
],
"파주시"
:
[
56
,
131
],
"이천시"
:
[
68
,
121
],
"안성시"
:
[
65
,
115
],
"김포시"
:
[
55
,
128
],
"화성시"
:
[
57
,
119
],
"광주시"
:
[
65
,
123
],
"양주시"
:
[
61
,
131
],
"포천시"
:
[
64
,
134
],
"여주시"
:
[
71
,
121
],
"연천군"
:
[
61
,
138
],
"가평군"
:
[
69
,
133
],
"양평군"
:
[
69
,
125
]
},
"강원도"
:
{
"춘천시"
:
[
73
,
134
],
"원주시"
:
[
76
,
122
],
"강릉시"
:
[
92
,
131
],
"동해시"
:
[
97
,
127
],
"태백시"
:
[
95
,
119
],
"속초시"
:
[
87
,
141
],
"삼척시"
:
[
98
,
125
],
"홍천군"
:
[
75
,
130
],
"횡성군"
:
[
77
,
125
],
"영월군"
:
[
86
,
119
],
"평창군"
:
[
84
,
123
],
"정선군"
:
[
89
,
123
],
"철원군"
:
[
65
,
139
],
"화천군"
:
[
72
,
139
],
"양구군"
:
[
77
,
139
],
"인제군"
:
[
80
,
138
],
"고성군"
:
[
85
,
145
],
"양양군"
:
[
88
,
138
]
},
"충청북도"
:
{
"청주시"
:
[
69
,
106
],
"충주시"
:
[
76
,
114
],
"제천시"
:
[
81
,
118
],
"보은군"
:
[
73
,
103
],
"옥천군"
:
[
71
,
99
],
"영동군"
:
[
74
,
97
],
"증평군"
:
[
71
,
110
],
"진천군"
:
[
68
,
111
],
"괴산군"
:
[
74
,
111
],
"음성군"
:
[
72
,
113
],
"단양군"
:
[
84
,
115
]
},
"충청남도"
:
{
"천안시"
:
[
63
,
110
],
"공주시"
:
[
63
,
102
],
"보령시"
:
[
54
,
100
],
"아산시"
:
[
60
,
110
],
"서산시"
:
[
51
,
110
],
"논산시"
:
[
62
,
97
],
"계룡시"
:
[
65
,
99
],
"당진시"
:
[
54
,
112
],
"금산군"
:
[
69
,
95
],
"부여군"
:
[
59
,
99
],
"서천군"
:
[
55
,
94
],
"청양군"
:
[
57
,
103
],
"홍성군"
:
[
55
,
106
],
"예산군"
:
[
58
,
107
],
"태안군"
:
[
48
,
109
]
},
"전라북도"
:
{
"전주시"
:
[
63
,
89
],
"군산시"
:
[
56
,
92
],
"익산시"
:
[
60
,
91
],
"정읍시"
:
[
58
,
83
],
"남원시"
:
[
68
,
80
],
"김제시"
:
[
59
,
88
],
"완주군"
:
[
63
,
89
],
"진안군"
:
[
68
,
88
],
"무주군"
:
[
72
,
93
],
"장수군"
:
[
70
,
85
],
"임실군"
:
[
66
,
84
],
"순창군"
:
[
63
,
79
],
"고창군"
:
[
56
,
80
],
"부안군"
:
[
56
,
87
]
},
"전라남도"
:
{
"목포시"
:
[
50
,
67
],
"여수시"
:
[
73
,
66
],
"순천시"
:
[
70
,
70
],
"나주시"
:
[
56
,
71
],
"광양시"
:
[
73
,
70
],
"담양군"
:
[
61
,
78
],
"곡성군"
:
[
66
,
77
],
"구례군"
:
[
69
,
75
],
"고흥군"
:
[
66
,
62
],
"보성군"
:
[
62
,
66
],
"화순군"
:
[
61
,
72
],
"장흥군"
:
[
59
,
64
],
"강진군"
:
[
57
,
63
],
"해남군"
:
[
54
,
61
],
"영암군"
:
[
56
,
66
],
"무안군"
:
[
52
,
71
],
"함평군"
:
[
52
,
72
],
"영광군"
:
[
52
,
77
],
"장성군"
:
[
57
,
77
],
"완도군"
:
[
57
,
56
],
"진도군"
:
[
48
,
59
],
"신안군"
:
[
50
,
66
]
},
"경상북도"
:
{
"포항시"
:
[
102
,
94
],
"경주시"
:
[
100
,
91
],
"김천시"
:
[
80
,
96
],
"안동시"
:
[
91
,
106
],
"구미시"
:
[
84
,
96
],
"영주시"
:
[
89
,
111
],
"영천시"
:
[
95
,
93
],
"상주시"
:
[
81
,
102
],
"문경시"
:
[
81
,
106
],
"경산시"
:
[
91
,
90
],
"군위군"
:
[
88
,
99
],
"의성군"
:
[
90
,
101
],
"청송군"
:
[
96
,
103
],
"영양군"
:
[
97
,
108
],
"영덕군"
:
[
102
,
103
],
"청도군"
:
[
91
,
86
],
"고령군"
:
[
83
,
87
],
"성주군"
:
[
83
,
91
],
"칠곡군"
:
[
85
,
93
],
"예천군"
:
[
86
,
107
],
"봉화군"
:
[
90
,
113
],
"울진군"
:
[
102
,
115
],
"울릉군"
:
[
127
,
127
]
},
"경상남도"
:
{
"창원시"
:
[
90
,
77
],
"진주시"
:
[
81
,
75
],
"통영시"
:
[
87
,
68
],
"사천시"
:
[
80
,
71
],
"김해시"
:
[
95
,
77
],
"밀양시"
:
[
92
,
83
],
"거제시"
:
[
90
,
69
],
"양산시"
:
[
97
,
79
],
"의령군"
:
[
83
,
78
],
"함안군"
:
[
86
,
77
],
"창녕군"
:
[
87
,
83
],
"고성군"
:
[
85
,
71
],
"남해군"
:
[
77
,
68
],
"하동군"
:
[
74
,
73
],
"산청군"
:
[
76
,
80
],
"함양군"
:
[
74
,
82
],
"거창군"
:
[
77
,
86
],
"합천군"
:
[
81
,
84
]
},
"제주특별자치도"
:
{
"제주시"
:
[
53
,
38
],
"서귀포시"
:
[
52
,
33
]
}
}
\ No newline at end of file
festivalList.json
0 → 100644
View file @
39dae05
{
"_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
server.js
View file @
39dae05
const
express
=
require
(
'express'
);
const
mongoose
=
require
(
'mongoose'
);
const
server
=
express
(
);
const
db
=
require
(
'mongodb'
);
const
Festival
=
require
(
'./models/Festival'
);
require
(
"dotenv"
).
config
({
path
:
"variables.env"
});
const
COORDINATES
=
require
(
'./coordinates'
);
const
DISTRICT
=
[
"서울특별시"
,
"부산광역시"
,
"울산광역시"
,
"대구광역시"
,
"대전광역시"
,
"인천광역시"
,
"광주광역시"
,
"세종특별자치시"
,
"제주특별자치도"
,
"경기도"
,
"강원도"
,
"충청북도"
,
"충청남도"
,
"경상북도"
,
"경상남도"
,
"전라북도"
,
"전라남도"
]
function
parseDistrict
(
addr
)
{
const
words
=
addr
.
split
(
" "
);
if
(
DISTRICT
.
includes
(
words
[
0
])
)
{
return
[
words
[
0
],
words
[
1
]];
}
else
{
return
[];
}
}
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=C&numOfRows=12&pageNo=1&_type=json'
,
'headers'
:
{
}
'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
);
mongoose
.
connect
(
process
.
env
.
MONGODB_URL
,{
useNewUrlParser
:
true
},(
err
)
=>
{
if
(
err
)
{
console
.
log
(
err
);
}
else
{
mongoose
.
connection
.
db
.
dropCollection
(
'festivals'
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
log
(
err
+
"Reset Failed!"
);
}
else
{
console
.
log
(
result
+
"Reset Success!"
);
request
(
options
,
async
function
(
error
,
response
,
body
)
{
if
(
error
)
{
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'
+
'&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'
,
'headers'
:
{}
},
'detail'
:
{
'method'
:
'GET'
,
'url'
:
'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?'
+
'ServiceKey='
+
'3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D'
+
'&contentTypeId='
+
'15'
+
'&contentId='
+
item
[
'contentid'
]
+
'&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'
:
{}
}
};
await
request
(
Info
.
public
,
async
function
(
error
,
response
,
body
)
{
if
(
error
)
{
throw
new
Error
(
error
);
}
let
pinfo
=
JSON
.
parse
(
body
);
let
distriction
=
parseDistrict
(
pinfo
[
'response'
][
'body'
][
'items'
][
'item'
][
'addr1'
]);
if
(
!
distriction
)
reject
(
"탈출"
);
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'
:
{
}
}
};
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'
});
});
});
});
}});
const
newFestival
=
new
Festival
();
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
.
district
=
distriction
[
0
];
// 광역시/도
newFestival
.
city
=
parseDistrict
[
1
];
// 시군구
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'
];
});
// let [nx, ny] = COORDINATES[distriction[0]][distriction[1]];
// Info.weather.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=' + nx
// + '&ny=' + ny;
server
.
listen
(
3000
,(
err
)
=>
{
if
(
err
){
return
console
.
log
(
err
);
}
else
{
mongoose
.
connect
(
process
.
env
.
MONGODB_URL
,{
useNewUrlParser
:
true
},(
err
)
=>
{
if
(
err
){
console
.
log
(
err
);
}
else
{
console
.
log
(
"Connected to database successfully"
);
// await 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('날씨 :맑음') ;}
// }
// }
// });
await
newFestival
.
save
().
then
((
festival
)
=>
{
console
.
log
(
festival
,
"Save success!"
);
});
})
/*.catch(error => {
console.log(error);
});*/
}
});
}
});
}
})
})
;
\ No newline at end of file
...
...
Please
register
or
login
to post a comment