APIhandler.js
4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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=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=' + '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']);
} 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('없음') ;}
}
}
});
}
});