Showing
2 changed files
with
134 additions
and
39 deletions
1 | let request = require('request'); | 1 | let request = require('request'); |
2 | let options = { | 2 | let options = { |
3 | 'method': 'GET', | 3 | 'method': 'GET', |
4 | - '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', | 4 | + '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', |
5 | 'headers': { | 5 | 'headers': { |
6 | } | 6 | } |
7 | }; | 7 | }; |
8 | +var contentId = new Array(); | ||
8 | request(options, function (error, response, body) { | 9 | request(options, function (error, response, body) { |
9 | if (error) { | 10 | if (error) { |
10 | - throw new Error(error); | 11 | + throw new Error(error); |
11 | } | 12 | } |
12 | - let info = JSON.parse(body); | 13 | +let info = JSON.parse(body); |
13 | - | 14 | +for(i in info['response']['body']['items']['item']){ |
14 | - for (i in info['response']['body']['items']['item']) { | 15 | + contentId[i]=info['response']['body']['items']['item'][i]['contentid']; |
15 | - console.log('축제 : ' + info['response']['body']['items']['item'][i]['title']); | 16 | + let Info ={ |
16 | - console.log('축제 주소 : ' + info['response']['body']['items']['item'][i]['addr1']); | 17 | + 'public':{ |
17 | - console.log( | 18 | + 'method': 'GET', |
18 | - '전화번호 : ' + info['response']['body']['items']['item'][i]['tel'] | 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', |
19 | - ); | 20 | + 'headers': {} |
20 | - console.log('축제위도 : ' + info['response']['body']['items']['item'][i]['mapx']); | 21 | + }, |
21 | - console.log('축제경도 : ' + info['response']['body']['items']['item'][i]['mapy']); | 22 | + 'detail':{ |
22 | - console.log(" ") | 23 | + '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', | ||
25 | + 'headers': {} | ||
26 | + }, | ||
27 | + 'weather': | ||
28 | + { | ||
29 | + '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', | ||
31 | + 'headers': {} | ||
32 | + } | ||
33 | + }; | ||
34 | + request(Info.public, function (error, response, body) { | ||
35 | + if (error) { | ||
36 | + throw new Error(error); | ||
37 | + } | ||
38 | + let pinfo = JSON.parse(body); | ||
39 | + console.log('축제 : ' + pinfo['response']['body']['items']['item']['title']); | ||
40 | + console.log('축제 주소 : ' + pinfo['response']['body']['items']['item']['addr1']); | ||
41 | + console.log('전화번호 : ' + pinfo['response']['body']['items']['item']['tel']); | ||
42 | + console.log('축제위도 : ' + pinfo['response']['body']['items']['item']['mapx']); | ||
43 | + console.log('축제경도 : ' + pinfo['response']['body']['items']['item']['mapy']); | ||
44 | + console.log('ID : ' + pinfo['response']['body']['items']['item']['contentid']); | ||
45 | + console.log('축제 정보 : ' + pinfo['response']['body']['items']['item']['overview']); | ||
46 | + console.log('이미지 Url : ' + pinfo['response']['body']['items']['item']['firstimage']); | ||
47 | + console.log('홈페이지 Url : ' + pinfo['response']['body']['items']['item']['homepage']); | ||
48 | + console.log('') | ||
49 | + }); | ||
50 | + request(Info.detail, function (error, response, body) { | ||
51 | + if (error) { | ||
52 | + throw new Error(error); | ||
53 | + } | ||
54 | + let dinfo = JSON.parse(body); | ||
55 | + console.log('축제 시작일 : ' + dinfo['response']['body']['items']['item']['eventstartdate']); | ||
56 | + console.log('축제 종료일 : ' + dinfo['response']['body']['items']['item']['eventenddate']); | ||
57 | + console.log('나이제한 : ' + dinfo['response']['body']['items']['item']['agelimit']); | ||
58 | + }); | ||
59 | + request(Info.weather, function (error, response, body) { | ||
60 | + if (error) { | ||
61 | + throw new Error(error); | ||
62 | + } | ||
63 | + let winfo = JSON.parse(body); | ||
64 | + | ||
65 | + for( let item of winfo['response']['body']['items']['item']) | ||
66 | + { | ||
67 | + | ||
68 | + if(item['category']=='TMP') | ||
69 | + { | ||
70 | + console.log('온도: '+item['fcstValue']); | ||
71 | + } | ||
72 | + if(item['category']=='PTY') | ||
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 | + }); | ||
23 | } | 84 | } |
24 | }); | 85 | }); |
25 | - | ||
... | \ 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 server = express(); |
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 | -let request = require('request'); | 7 | +let request = require('request-promise-native'); |
8 | let options = { | 8 | let options = { |
9 | 'method': 'GET', | 9 | '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=A&numOfRows=12&pageNo=1&_type=json', | 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', |
11 | 'headers': { | 11 | 'headers': { |
12 | } | 12 | } |
13 | }; | 13 | }; |
14 | +var contentId = new Array(); | ||
15 | + | ||
14 | request(options, function (error, response, body) { | 16 | request(options, function (error, response, body) { |
15 | if (error) { | 17 | if (error) { |
16 | throw new Error(error); | 18 | throw new Error(error); |
17 | } | 19 | } |
18 | let info = JSON.parse(body); | 20 | let info = JSON.parse(body); |
19 | 21 | ||
22 | + for(i in info['response']['body']['items']['item']){ | ||
23 | + contentId[i]=info['response']['body']['items']['item'][7]['contentid']; | ||
24 | + let Info ={ | ||
25 | + 'public':{ | ||
26 | + 'method': 'GET', | ||
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', | ||
28 | + 'headers': { | ||
29 | + } | ||
30 | + }, | ||
31 | + 'detail':{ | ||
32 | + 'method': 'GET', | ||
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', | ||
34 | + 'headers': { | ||
35 | + } | ||
36 | + } | ||
37 | + }; | ||
20 | 38 | ||
21 | - | 39 | + request(Info.public,function (error, response, body) { |
22 | - server.get('/',(req,res)=>{ | 40 | + if (error) { |
23 | - const newFestival =new Festival(); | 41 | + throw new Error(error); |
24 | - newFestival.title =info['response']['body']['items']['item'][11]['title']; | 42 | + } |
25 | - newFestival.addr =info['response']['body']['items']['item'][11]['addr1']; | 43 | + let pinfo = JSON.parse(body); |
26 | - newFestival.tel = info['response']['body']['items']['item'][11]['tel']; | 44 | + server.get('/', async (req,res)=>{ |
27 | - newFestival.mapx = info['response']['body']['items']['item'][11]['mapx']; | 45 | + const newFestival = new Festival(); |
28 | - newFestival.mapy =info['response']['body']['items']['item'][11]['mapy']; | 46 | + await request(Info.detail, function (error, response, body) { |
29 | - newFestival.save().then((festival)=> | 47 | + if (error) { |
30 | - { | 48 | + throw new Error(error); |
31 | - console.log(festival); | 49 | + } |
32 | - res.json({ | 50 | + let dinfo = JSON.parse(body); |
33 | - message:'Festival Created Successfully' | 51 | + newFestival.eventstartdate = dinfo['response']['body']['items']['item']['eventstartdate']; |
34 | - }); | 52 | + newFestival.eventenddate = dinfo['response']['body']['items']['item']['eventenddate']; |
35 | - }) | 53 | + }); |
36 | - .catch((err)=> | 54 | + newFestival.title = pinfo['response']['body']['items']['item']['title']; |
37 | - { | 55 | + newFestival.addr = pinfo['response']['body']['items']['item']['addr1']; |
38 | - res.json({ | 56 | + newFestival.tel = pinfo['response']['body']['items']['item']['tel']; |
39 | - message:'Festival was not successfully created' | 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 | + }); | ||
40 | }); | 75 | }); |
41 | }); | 76 | }); |
42 | - }); | 77 | + }); |
43 | -}); | 78 | +}}); |
44 | 79 | ||
45 | server.listen(3000,(err)=>{ | 80 | server.listen(3000,(err)=>{ |
46 | if(err){ | 81 | if(err){ | ... | ... |
-
Please register or login to post a comment