hellowhales

Add weather info

...@@ -5,6 +5,7 @@ let options = { ...@@ -5,6 +5,7 @@ let options = {
5 'headers': { 5 'headers': {
6 } 6 }
7 }; 7 };
8 +
8 var contentId = new Array(); 9 var contentId = new Array();
9 request(options, function (error, response, body) { 10 request(options, function (error, response, body) {
10 if (error) { 11 if (error) {
...@@ -14,20 +15,35 @@ let info = JSON.parse(body); ...@@ -14,20 +15,35 @@ let info = JSON.parse(body);
14 for(i in info['response']['body']['items']['item']){ 15 for(i in info['response']['body']['items']['item']){
15 contentId[i]=info['response']['body']['items']['item'][i]['contentid']; 16 contentId[i]=info['response']['body']['items']['item'][i]['contentid'];
16 let Info ={ 17 let Info ={
17 - 'public':{ 18 + 'public': {
18 - 'method': 'GET', 19 + 'method': 'GET',
19 - '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', 20 + 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?'
20 - 'headers': {} 21 + + 'ServiceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D'
22 + + '&contentTypeId=' + '15'
23 + + '&contentId=' + +contentId[i]
24 + + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&defaultYN=Y&firstImageYN=Y&areacodeYN=Y&catcodeYN=Y&addrinfoYN=Y&mapinfoYN=Y&overviewYN=Y&transGuideYN=Y&_type=json',
25 + 'headers': {}
21 }, 26 },
22 - 'detail':{ 27 + 'detail': {
23 - 'method': 'GET', 28 + 'method': 'GET',
24 - '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', 29 + 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?'
25 - 'headers': {} 30 + + 'ServiceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D'
31 + + '&contentTypeId=' + '15'
32 + + '&contentId=' + contentId[i]
33 + + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&introYN=Y&_type=json',
34 + 'headers': {}
26 }, 35 },
27 - 'weather': 36 + 'weather': {
28 - {
29 'method': 'GET', 37 'method': 'GET',
30 - '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', 38 + 'url': 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst?'
39 + + 'serviceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D'
40 + + '&pageNo=' + '1'
41 + + '&numOfRows=' + '50'
42 + + '&dataType=' + 'JSON'
43 + + '&base_date=' + '20211129'
44 + + '&base_time=' + '0500'
45 + + '&nx=' + '55 '
46 + + '&ny=' + '127',
31 'headers': {} 47 'headers': {}
32 } 48 }
33 }; 49 };
...@@ -56,30 +72,26 @@ for(i in info['response']['body']['items']['item']){ ...@@ -56,30 +72,26 @@ for(i in info['response']['body']['items']['item']){
56 console.log('축제 종료일 : ' + dinfo['response']['body']['items']['item']['eventenddate']); 72 console.log('축제 종료일 : ' + dinfo['response']['body']['items']['item']['eventenddate']);
57 console.log('나이제한 : ' + dinfo['response']['body']['items']['item']['agelimit']); 73 console.log('나이제한 : ' + dinfo['response']['body']['items']['item']['agelimit']);
58 }); 74 });
59 - request(Info.weather, function (error, response, body) { 75 + request(Info.weather, function (error, response, body) {
60 if (error) { 76 if (error) {
61 - throw new Error(error); 77 + throw new Error(error);
62 } 78 }
63 - let winfo = JSON.parse(body); 79 + let winfo = JSON.parse(body);
64 -
65 - for( let item of winfo['response']['body']['items']['item'])
66 - {
67 80
68 - if(item['category']=='TMP') 81 + for( let item of winfo['response']['body']['items']['item']) {
69 - { 82 +
70 - console.log('온도: '+item['fcstValue']); 83 + if(item['category']=='TMP') {
84 + console.log('온도: '+item['fcstValue']);
85 + } else if(item['category']=='PTY') {
86 + let weather_code = item['fcstValue']
87 +
88 + if (weather_code == '1'){ console.log('날씨 : 비');}
89 + else if (weather_code == '2'){ console.log('날씨 :비/눈') ;}
90 + else if (weather_code == '3'){ console.log('날씨 :눈') ;}
91 + else if (weather_code == '4'){ console.log('날씨 :소나기') ;}
92 + else{console.log('없음') ;}
93 + }
71 } 94 }
72 - if(item['category']=='PTY') 95 + });
73 - {
74 - let weather_code = item['fcstValue']
75 -
76 - if (weather_code == '1'){ console.log('날씨 : 비');}
77 - else if (weather_code == '2'){ console.log('날씨 :비/눈') ;}
78 - else if (weather_code == '3'){ console.log('날씨 :눈') ;}
79 - else if (weather_code == '4'){ console.log('날씨 :소나기') ;}
80 - else{console.log('없음') ;}
81 - }
82 - }
83 - });
84 } 96 }
85 }); 97 });
......
1 +exports.COORDINATES = {
2 + "서울특별시" : {
3 + "종로구" : [60, 127],
4 + "중구" : [60, 127],
5 + "용산구" : [60, 126],
6 + "성동구" : [61, 127],
7 + "광진구" : [62, 126],
8 + "동대문구" : [61, 127],
9 + "중랑구" : [62, 128],
10 + "성북구" : [61, 127],
11 + "강북구" : [61, 128],
12 + "도봉구" : [61, 129],
13 + "노원구" : [61, 129],
14 + "은평구" : [59, 127],
15 + "서대문구" : [59, 127],
16 + "마포구" : [59, 127],
17 + "양천구" : [58, 126],
18 + "강서구" : [58, 126],
19 + "구로구" : [58, 125],
20 + "금천구" : [59, 124],
21 + "영등포구" : [58, 126],
22 + "동작구" : [59, 125],
23 + "관악구" : [59, 125],
24 + "서초구" : [61, 125],
25 + "강남구" : [61, 126],
26 + "송파구" : [62, 126],
27 + "강동구" : [62, 126]
28 + },
29 + "부산광역시" : {
30 + "중구" : [97, 74],
31 + "서구" : [97, 74],
32 + "동구" : [98, 75],
33 + "영도구" : [98, 74],
34 + "부산진구" : [97, 75],
35 + "동래구" : [98, 76],
36 + "남구" : [98, 75],
37 + "북구" : [96, 76],
38 + "해운대구" : [99, 75],
39 + "사하구" : [96, 74],
40 + "금정구" : [98, 77],
41 + "강서구" : [96, 76],
42 + "연제구" : [98, 76],
43 + "수영구" : [99, 75],
44 + "사상구" : [96, 75],
45 + "기장군" : [100, 77]
46 + },
47 + "대구광역시" : {
48 + "중구" : [89, 90],
49 + "동구" : [90, 91],
50 + "서구" : [88, 90],
51 + "남구" : [89, 90],
52 + "북구" : [89, 91],
53 + "수성구" : [89, 90],
54 + "달서구" : [88, 90],
55 + "달성군" : [86, 88]
56 + },
57 + "인천광역시" : {
58 + "중구" : [54, 125],
59 + "동구" : [54, 125],
60 + "미추홀구" : [54, 124],
61 + "연수구" : [55, 123],
62 + "남동구" : [56, 124],
63 + "부평구" : [55, 125],
64 + "계양구" : [56, 126],
65 + "서구" : [55, 126],
66 + "강화군" : [51, 130],
67 + "옹진군" : [54, 124]
68 + },
69 + "광주광역시" : {
70 + "동구" : [60, 74],
71 + "서구" : [59, 74],
72 + "남구" : [59, 73],
73 + "북구" : [59, 75],
74 + "광산구" : [57, 74]
75 + },
76 + "대전광역시" : {
77 + "동구" : [68, 100],
78 + "중구" : [68, 100],
79 + "서구" : [67, 100],
80 + "유성구" : [67, 101],
81 + "대덕구" : [68, 100]
82 + },
83 + "울산광역시" : {
84 + "중구" : [102, 84],
85 + "남구" : [102, 84],
86 + "동구" : [104, 83],
87 + "북구" : [103, 85],
88 + "울주군" : [101, 84]
89 + },
90 + "세종특별자치시" : {
91 + "세종특별자치시": [66, 103]
92 + },
93 + "경기도" : {
94 + "수원시" : [61, 120],
95 + "성남시" : [63, 124],
96 + "의정부시" : [61, 130],
97 + "안양시" : [59, 123],
98 + "부천시" : [56, 125],
99 + "광명시" : [58, 125],
100 + "평택시" : [62, 114],
101 + "동두천시" : [61, 134],
102 + "안산시" : [58, 121],
103 + "고양시" : [57, 128],
104 + "과천시" : [60, 124],
105 + "구리시" : [62, 127],
106 + "남양주시" : [64, 128],
107 + "오산시" : [62, 118],
108 + "시흥시" : [57, 123],
109 + "군포시" : [59, 122],
110 + "의왕시" : [60, 122],
111 + "하남시" : [64, 126],
112 + "용인시" : [64, 119],
113 + "파주시" : [56, 131],
114 + "이천시" : [68, 121],
115 + "안성시" : [65, 115],
116 + "김포시" : [55, 128],
117 + "화성시" : [57, 119],
118 + "광주시" : [65, 123],
119 + "양주시" : [61, 131],
120 + "포천시" : [64, 134],
121 + "여주시" : [71, 121],
122 + "연천군" : [61, 138],
123 + "가평군" : [69, 133],
124 + "양평군" : [69, 125]
125 + },
126 + "강원도" : {
127 + "춘천시" : [73, 134],
128 + "원주시" : [76, 122],
129 + "강릉시" : [92, 131],
130 + "동해시" : [97, 127],
131 + "태백시" : [95, 119],
132 + "속초시" : [87, 141],
133 + "삼척시" : [98, 125],
134 + "홍천군" : [75, 130],
135 + "횡성군" : [77, 125],
136 + "영월군" : [86, 119],
137 + "평창군" : [84, 123],
138 + "정선군" : [89, 123],
139 + "철원군" : [65, 139],
140 + "화천군" : [72, 139],
141 + "양구군" : [77, 139],
142 + "인제군" : [80, 138],
143 + "고성군" : [85, 145],
144 + "양양군" : [88, 138]
145 + },
146 + "충청북도" : {
147 + "청주시" : [69, 106],
148 + "충주시" : [76, 114],
149 + "제천시" : [81, 118],
150 + "보은군" : [73, 103],
151 + "옥천군" : [71, 99],
152 + "영동군" : [74, 97],
153 + "증평군" : [71, 110],
154 + "진천군" : [68, 111],
155 + "괴산군" : [74, 111],
156 + "음성군" : [72, 113],
157 + "단양군" : [84, 115]
158 + },
159 + "충청남도" : {
160 + "천안시" : [63, 110],
161 + "공주시" : [63, 102],
162 + "보령시" : [54, 100],
163 + "아산시" : [60, 110],
164 + "서산시" : [51, 110],
165 + "논산시" : [62, 97],
166 + "계룡시" : [65, 99],
167 + "당진시" : [54, 112],
168 + "금산군" : [69, 95],
169 + "부여군" : [59, 99],
170 + "서천군" : [55, 94],
171 + "청양군" : [57, 103],
172 + "홍성군" : [55, 106],
173 + "예산군" : [58, 107],
174 + "태안군" : [48, 109]
175 + },
176 + "전라북도" : {
177 + "전주시" : [63, 89],
178 + "군산시" : [56, 92],
179 + "익산시" : [60, 91],
180 + "정읍시" : [58, 83],
181 + "남원시" : [68, 80],
182 + "김제시" : [59, 88],
183 + "완주군" : [63, 89],
184 + "진안군" : [68, 88],
185 + "무주군" : [72, 93],
186 + "장수군" : [70, 85],
187 + "임실군" : [66, 84],
188 + "순창군" : [63, 79],
189 + "고창군" : [56, 80],
190 + "부안군" : [56, 87]
191 + },
192 + "전라남도" : {
193 + "목포시" : [50, 67],
194 + "여수시" : [73, 66],
195 + "순천시" : [70, 70],
196 + "나주시" : [56, 71],
197 + "광양시" : [73, 70],
198 + "담양군" : [61, 78],
199 + "곡성군" : [66, 77],
200 + "구례군" : [69, 75],
201 + "고흥군" : [66, 62],
202 + "보성군" : [62, 66],
203 + "화순군" : [61, 72],
204 + "장흥군" : [59, 64],
205 + "강진군" : [57, 63],
206 + "해남군" : [54, 61],
207 + "영암군" : [56, 66],
208 + "무안군" : [52, 71],
209 + "함평군" : [52, 72],
210 + "영광군" : [52, 77],
211 + "장성군" : [57, 77],
212 + "완도군" : [57, 56],
213 + "진도군" : [48, 59],
214 + "신안군" : [50, 66]
215 + },
216 + "경상북도" : {
217 + "포항시" : [102, 94],
218 + "경주시" : [100, 91],
219 + "김천시" : [80, 96],
220 + "안동시" : [91, 106],
221 + "구미시" : [84, 96],
222 + "영주시" : [89, 111],
223 + "영천시" : [95, 93],
224 + "상주시" : [81, 102],
225 + "문경시" : [81, 106],
226 + "경산시" : [91, 90],
227 + "군위군" : [88, 99],
228 + "의성군" : [90, 101],
229 + "청송군" : [96, 103],
230 + "영양군" : [97, 108],
231 + "영덕군" : [102, 103],
232 + "청도군" : [91, 86],
233 + "고령군" : [83, 87],
234 + "성주군" : [83, 91],
235 + "칠곡군" : [85, 93],
236 + "예천군" : [86, 107],
237 + "봉화군" : [90, 113],
238 + "울진군" : [102, 115],
239 + "울릉군" : [127, 127]
240 + },
241 + "경상남도" : {
242 + "창원시" : [90, 77],
243 + "진주시" : [81, 75],
244 + "통영시" : [87, 68],
245 + "사천시" : [80, 71],
246 + "김해시" : [95, 77],
247 + "밀양시" : [92, 83],
248 + "거제시" : [90, 69],
249 + "양산시" : [97, 79],
250 + "의령군" : [83, 78],
251 + "함안군" : [86, 77],
252 + "창녕군" : [87, 83],
253 + "고성군" : [85, 71],
254 + "남해군" : [77, 68],
255 + "하동군" : [74, 73],
256 + "산청군" : [76, 80],
257 + "함양군" : [74, 82],
258 + "거창군" : [77, 86],
259 + "합천군" : [81, 84]
260 + },
261 + "제주특별자치도" : {
262 + "제주시" : [53, 38],
263 + "서귀포시" : [52, 33]
264 + }
265 +}
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "_id": {
3 + "$oid": "619a35f2a96f26c4d20a5122"
4 + },
5 + "title": "《MMCA 이건희컬렉션 특별전: 한국미술명작》",
6 + "addr": "서울특별시 종로구 삼청로 30",
7 + "tel": "02-3701-9500",
8 + "mapx": 126.9800649747,
9 + "mapy": 37.5788361778,
10 + "createdAt": {
11 + "$date": "2021-11-21T12:05:06.042Z"
12 + },
13 + "updatedAt": {
14 + "$date": "2021-11-21T12:05:06.042Z"
15 + },
16 + "__v": 0
17 +}
18 +
19 +{
20 + "_id": {
21 + "$oid": "619a361f6a4cad598e278632"
22 + },
23 + "title": "가무악극으로 만나는 토요 상설공연",
24 + "addr": "충청남도 부여군 규암면 백제문로 388",
25 + "tel": "041-832-5765",
26 + "mapx": 126.8997016069,
27 + "mapy": 36.3048428766,
28 + "createdAt": {
29 + "$date": "2021-11-21T12:05:51.663Z"
30 + },
31 + "updatedAt": {
32 + "$date": "2021-11-21T12:05:51.663Z"
33 + },
34 + "__v": 0
35 +}
36 +{
37 + "_id": {
38 + "$oid": "619a3642f8e65868598b5a17"
39 + },
40 + "title": "가산수피아 '봄의 정원'",
41 + "addr": "경상북도 칠곡군 가산면 학하들안2길 105",
42 + "tel": "054-971-9861",
43 + "mapx": 128.4850691574,
44 + "mapy": 36.0861545517,
45 + "createdAt": {
46 + "$date": "2021-11-21T12:06:26.416Z"
47 + },
48 + "updatedAt": {
49 + "$date": "2021-11-21T12:06:26.416Z"
50 + },
51 + "__v": 0
52 +}
53 +{
54 + "_id": {
55 + "$oid": "619a3663a1816be4d2a4882b"
56 + },
57 + "title": "가족끼리 빙어체험 2021",
58 + "addr": "경기도 양평군 단월면 곱다니길 55-2 수미마을 방문객센터",
59 + "tel": "031-775-5205",
60 + "mapx": 127.6574135888,
61 + "mapy": 37.514550408,
62 + "createdAt": {
63 + "$date": "2021-11-21T12:06:59.535Z"
64 + },
65 + "updatedAt": {
66 + "$date": "2021-11-21T12:06:59.535Z"
67 + },
68 + "__v": 0
69 +}
70 +{
71 + "_id": {
72 + "$oid": "619a3688b715b78b16cc6208"
73 + },
74 + "title": "가족끼리딸기 캠피닉",
75 + "addr": "경기도 양평군 단월면 곱다니길 55-2",
76 + "tel": "031-775-5205",
77 + "mapx": 127.657366373,
78 + "mapy": 37.5144948588,
79 + "createdAt": {
80 + "$date": "2021-11-21T12:07:36.556Z"
81 + },
82 + "updatedAt": {
83 + "$date": "2021-11-21T12:07:36.556Z"
84 + },
85 + "__v": 0
86 +}
87 +{
88 + "_id": {
89 + "$oid": "619a36abc8bcb135bf91ff48"
90 + },
91 + "title": "가족오페라 <마술피리> 2021",
92 + "addr": "대구광역시 북구 호암로 15",
93 + "tel": "053-666-6170",
94 + "mapx": 128.592257023,
95 + "mapy": 35.8835072863,
96 + "createdAt": {
97 + "$date": "2021-11-21T12:08:11.131Z"
98 + },
99 + "updatedAt": {
100 + "$date": "2021-11-21T12:08:11.131Z"
101 + },
102 + "__v": 0
103 +}
104 +{
105 + "_id": {
106 + "$oid": "619a36d2623874f5ebdb540d"
107 + },
108 + "title": "감악산 꽃&별 여행",
109 + "addr": "거창군 신원면 덕산리 산 57",
110 + "tel": "055-940-3390",
111 + "mapx": 127.9163995903,
112 + "mapy": 35.5912836573,
113 + "createdAt": {
114 + "$date": "2021-11-21T12:08:50.766Z"
115 + },
116 + "updatedAt": {
117 + "$date": "2021-11-21T12:08:50.766Z"
118 + },
119 + "__v": 0
120 +}
121 +{
122 + "_id": {
123 + "$oid": "619a36ff8d2678a5079637ab"
124 + },
125 + "title": "강동북페스티벌",
126 + "addr": "온라인 개최",
127 + "tel": "강일 427-4004, 성내 471-0044, 해공 478-9656, 암사 429-0476, 천호 488-7223, 둔촌 489-6557",
128 + "mapx": 127.1573829418,
129 + "mapy": 37.5512675743,
130 + "createdAt": {
131 + "$date": "2021-11-21T12:09:35.075Z"
132 + },
133 + "updatedAt": {
134 + "$date": "2021-11-21T12:09:35.075Z"
135 + },
136 + "__v": 0
137 +}
138 +{
139 + "_id": {
140 + "$oid": "619a37162e9742f8315195ed"
141 + },
142 + "title": "강동선사문화축제",
143 + "addr": "서울특별시 강동구 성내로 25",
144 + "tel": "02-3425-8530",
145 + "mapx": 127.1237865998,
146 + "mapy": 37.530177751,
147 + "createdAt": {
148 + "$date": "2021-11-21T12:09:58.635Z"
149 + },
150 + "updatedAt": {
151 + "$date": "2021-11-21T12:09:58.635Z"
152 + },
153 + "__v": 0
154 +}
155 +{
156 + "_id": {
157 + "$oid": "619a3733fc3082f196a0a589"
158 + },
159 + "title": "강동청년축제",
160 + "tel": "02-482-7647",
161 + "createdAt": {
162 + "$date": "2021-11-21T12:10:27.165Z"
163 + },
164 + "updatedAt": {
165 + "$date": "2021-11-21T12:10:27.165Z"
166 + },
167 + "__v": 0
168 +}
169 +{
170 + "_id": {
171 + "$oid": "619a379163ec5352d3c1bae6"
172 + },
173 + "title": "강릉 단오제",
174 + "addr": "강원도 강릉시 단오장길 1",
175 + "tel": "033-641-1593",
176 + "mapx": 128.8950169869,
177 + "mapy": 37.7482134974,
178 + "createdAt": {
179 + "$date": "2021-11-21T12:12:01.456Z"
180 + },
181 + "updatedAt": {
182 + "$date": "2021-11-21T12:12:01.456Z"
183 + },
184 + "__v": 0
185 +}
186 +{
187 + "_id": {
188 + "$oid": "619a37aba63f1a25f61a4f5e"
189 + },
190 + "title": "강릉국제영화제(GIFF)",
191 + "addr": "강원도 강릉시 경강로2021번길 9-1",
192 + "tel": "033-641-8079",
193 + "mapx": 128.8898396064,
194 + "mapy": 37.7504353618,
195 + "createdAt": {
196 + "$date": "2021-11-21T12:12:27.604Z"
197 + },
198 + "updatedAt": {
199 + "$date": "2021-11-21T12:12:27.604Z"
200 + },
201 + "__v": 0
202 +}
...\ No newline at end of file ...\ No newline at end of file
1 const express = require('express'); 1 const express = require('express');
2 const mongoose = require('mongoose'); 2 const mongoose = require('mongoose');
3 -const server = express(); 3 +const db = require('mongodb');
4 const Festival = require('./models/Festival'); 4 const Festival = require('./models/Festival');
5 require("dotenv").config({ path: "variables.env"}); 5 require("dotenv").config({ path: "variables.env"});
6 6
7 +const COORDINATES = require('./coordinates');
8 +const DISTRICT = [
9 + "서울특별시", "부산광역시", "울산광역시", "대구광역시", "대전광역시",
10 + "인천광역시", "광주광역시", "세종특별자치시", "제주특별자치도",
11 + "경기도", "강원도", "충청북도", "충청남도", "경상북도",
12 + "경상남도", "전라북도", "전라남도"
13 +]
14 +function parseDistrict(addr) {
15 + const words = addr.split(" ");
16 + if( DISTRICT.includes(words[0]) ) {
17 + return [words[0], words[1]];
18 + } else {
19 + return [];
20 + }
21 +}
22 +
7 let request = require('request-promise-native'); 23 let request = require('request-promise-native');
8 let options = { 24 let options = {
9 'method': 'GET', 25 'method': 'GET',
10 - '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', 26 + 'url' : 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList'
11 - 'headers': { 27 + + '?ServiceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D'
12 - } 28 + + '&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=C&numOfRows=12'
29 + + '&pageNo='+ 1
30 + + '&_type=json',
31 +
32 + 'headers': {}
13 }; 33 };
14 -var contentId = new Array();
15 34
16 -request(options, function (error, response, body) { 35 +mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{
17 - if (error) { 36 + if(err) {
18 - throw new Error(error); 37 + console.log(err);
19 - } 38 + } else {
20 - let info = JSON.parse(body); 39 + mongoose.connection.db.dropCollection('festivals',function(err, result) {
40 + if(err) {
41 + console.log(err + "Reset Failed!");
42 + } else {
43 + console.log(result + "Reset Success!");
44 + request(options, async function (error, response, body) {
45 + if (error) {
46 + throw new Error(error);
47 + }
48 + let info = JSON.parse(body);
49 + let items = info['response']['body']['items']['item'];
50 + for(item of items) {
51 + let Info = {
52 + 'public': {
53 + 'method': 'GET',
54 + 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?'
55 + + 'ServiceKey=' + '3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D'
56 + + '&contentTypeId=' + '15'
57 + + '&contentId=' + item['contentid']
58 + + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&defaultYN=Y&firstImageYN=Y&areacodeYN=Y&catcodeYN=Y&addrinfoYN=Y&mapinfoYN=Y&overviewYN=Y&transGuideYN=Y&_type=json',
59 + 'headers': {}
60 + },
61 + 'detail': {
62 + 'method': 'GET',
63 + 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?'
64 + + 'ServiceKey=' + '3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D'
65 + + '&contentTypeId=' + '15'
66 + + '&contentId=' + item['contentid']
67 + + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&introYN=Y&_type=json',
68 + 'headers': {}
69 + },
70 + 'weather': {
71 + 'method': 'GET',
72 + 'url': 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst?'
73 + + 'serviceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D'
74 + + '&pageNo=' + '1'
75 + + '&numOfRows=' + '50'
76 + + '&dataType=' + 'JSON'
77 + + '&base_date=' + '20211129'
78 + + '&base_time=' + '0500'
79 + + '&nx=' + '55'
80 + + '&ny=' + '127',
81 + 'headers': {}
82 + }
83 + };
84 + await request(Info.public, async function (error, response, body) {
85 + if (error) {
86 + throw new Error(error);
87 + }
88 + let pinfo = JSON.parse(body);
89 + let distriction = parseDistrict(pinfo['response']['body']['items']['item']['addr1']);
90 + if (!distriction) reject("탈출");
21 91
22 - for(i in info['response']['body']['items']['item']){ 92 + const newFestival = new Festival();
23 - contentId[i]=info['response']['body']['items']['item'][7]['contentid']; 93 + newFestival.title = pinfo['response']['body']['items']['item']['title'];
24 - let Info ={ 94 + newFestival.addr = pinfo['response']['body']['items']['item']['addr1'];
25 - 'public':{ 95 + newFestival.tel = pinfo['response']['body']['items']['item']['tel'];
26 - 'method': 'GET', 96 + newFestival.mapx = pinfo['response']['body']['items']['item']['mapx'];
27 - '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', 97 + newFestival.mapy = pinfo['response']['body']['items']['item']['mapy'];
28 - 'headers': { 98 + newFestival.overview= pinfo['response']['body']['items']['item']['overview'];
29 - } 99 + newFestival.firstimage = pinfo['response']['body']['items']['item']['firstimage'];
30 - }, 100 + newFestival.homepage = pinfo ['response']['body']['items']['item']['homepage'];
31 - 'detail':{ 101 + newFestival.district = distriction[0]; // 광역시/도
32 - 'method': 'GET', 102 + newFestival.city = parseDistrict[1]; // 시군구
33 - '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', 103 +
34 - 'headers': { 104 + await request(Info.detail, function (error, response, body) {
35 - } 105 + if (error) {
36 - } 106 + throw new Error(error);
37 - }; 107 + }
38 - 108 + let dinfo = JSON.parse(body);
39 - request(Info.public,function (error, response, body) { 109 + newFestival.eventstartdate = dinfo['response']['body']['items']['item']['eventstartdate'];
40 - if (error) { 110 + newFestival.eventenddate = dinfo['response']['body']['items']['item']['eventenddate'];
41 - throw new Error(error); 111 + });
42 - } 112 +
43 - let pinfo = JSON.parse(body); 113 + // let [nx, ny] = COORDINATES[distriction[0]][distriction[1]];
44 - server.get('/', async (req,res)=>{ 114 +
45 - const newFestival = new Festival(); 115 + // Info.weather.url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst?'
46 - await request(Info.detail, function (error, response, body) { 116 + // + 'serviceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D'
47 - if (error) { 117 + // + '&pageNo=' + '1'
48 - throw new Error(error); 118 + // + '&numOfRows=' + '50'
49 - } 119 + // + '&dataType=' + 'JSON'
50 - let dinfo = JSON.parse(body); 120 + // + '&base_date=' + '20211129'
51 - newFestival.eventstartdate = dinfo['response']['body']['items']['item']['eventstartdate']; 121 + // + '&base_time=' + '0500'
52 - newFestival.eventenddate = dinfo['response']['body']['items']['item']['eventenddate']; 122 + // + '&nx=' + nx
53 - }); 123 + // + '&ny=' + ny;
54 - newFestival.title = pinfo['response']['body']['items']['item']['title'];
55 - newFestival.addr = pinfo['response']['body']['items']['item']['addr1'];
56 - newFestival.tel = pinfo['response']['body']['items']['item']['tel'];
57 - newFestival.mapx = pinfo['response']['body']['items']['item']['mapx'];
58 - newFestival.mapy = pinfo['response']['body']['items']['item']['mapy'];
59 - newFestival.overview= pinfo['response']['body']['items']['item']['overview'];
60 - newFestival.firstimage = pinfo['response']['body']['items']['item']['firstimage'];
61 - newFestival.homepage = pinfo ['response']['body']['items']['item']['homepage'];
62 -
63 - newFestival.save().then((festival) =>
64 - {
65 - console.log(festival, "Save success!");
66 - res.json({
67 - message:'Festival Created Successfully'
68 - });
69 - })
70 - .catch((err)=>
71 - {
72 - res.json({
73 - message:'Festival was not successfully created'
74 - });
75 - });
76 - });
77 - });
78 -}});
79 124
80 -server.listen(3000,(err)=>{ 125 + // await request(Info.weather, function (error, response, body) {
81 - if(err){ 126 + // if (error) {
82 - return console.log(err); 127 + // throw new Error(error);
83 - }else{ 128 + // }
84 - mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{ 129 + // let winfo = JSON.parse(body);
85 - if(err){ 130 +
86 - console.log(err); 131 + // for( let item of winfo['response']['body']['items']['item'] ) {
87 - }else{ 132 +
88 - console.log("Connected to database successfully"); 133 + // if(item['category']=='TMP') {
134 + // console.log('온도: '+item['fcstValue']);
135 + // } else if(item['category']=='PTY') {
136 + // let weather_code = item['fcstValue']
137 +
138 + // if (weather_code == '1'){ console.log('날씨 : 비');}
139 + // else if (weather_code == '2'){ console.log('날씨 :비/눈') ;}
140 + // else if (weather_code == '3'){ console.log('날씨 :눈') ;}
141 + // else if (weather_code == '4'){ console.log('날씨 :소나기') ;}
142 + // else{console.log('날씨 :맑음') ;}
143 + // }
144 + // }
145 + // });
146 +
147 + await newFestival.save().then((festival) => {
148 + console.log(festival, "Save success!");
149 + });
150 + })/*.catch(error => {
151 + console.log(error);
152 + });*/
153 + }
154 + });
89 } 155 }
90 }); 156 });
91 } 157 }
92 -}) 158 +});
...\ No newline at end of file ...\ No newline at end of file
......