Showing
3 changed files
with
148 additions
and
121 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=C&numOfRows=12&pageNo=1&_type=json', | 4 | + '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', |
| 5 | 'headers': { | 5 | 'headers': { |
| 6 | } | 6 | } |
| 7 | }; | 7 | }; |
| ... | @@ -18,7 +18,7 @@ for(i in info['response']['body']['items']['item']){ | ... | @@ -18,7 +18,7 @@ for(i in info['response']['body']['items']['item']){ |
| 18 | 'public': { | 18 | 'public': { |
| 19 | 'method': 'GET', | 19 | 'method': 'GET', |
| 20 | 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?' | 20 | 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?' |
| 21 | - + 'ServiceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D' | 21 | + + 'ServiceKey=' + '3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D' |
| 22 | + '&contentTypeId=' + '15' | 22 | + '&contentTypeId=' + '15' |
| 23 | + '&contentId=' + +contentId[i] | 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', | 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', |
| ... | @@ -27,7 +27,7 @@ for(i in info['response']['body']['items']['item']){ | ... | @@ -27,7 +27,7 @@ for(i in info['response']['body']['items']['item']){ |
| 27 | 'detail': { | 27 | 'detail': { |
| 28 | 'method': 'GET', | 28 | 'method': 'GET', |
| 29 | 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?' | 29 | 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?' |
| 30 | - + 'ServiceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D' | 30 | + + 'ServiceKey=' + '3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D' |
| 31 | + '&contentTypeId=' + '15' | 31 | + '&contentTypeId=' + '15' |
| 32 | + '&contentId=' + contentId[i] | 32 | + '&contentId=' + contentId[i] |
| 33 | + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&introYN=Y&_type=json', | 33 | + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&introYN=Y&_type=json', |
| ... | @@ -36,7 +36,7 @@ for(i in info['response']['body']['items']['item']){ | ... | @@ -36,7 +36,7 @@ for(i in info['response']['body']['items']['item']){ |
| 36 | 'weather': { | 36 | 'weather': { |
| 37 | 'method': 'GET', | 37 | 'method': 'GET', |
| 38 | 'url': 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst?' | 38 | 'url': 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst?' |
| 39 | - + 'serviceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D' | 39 | + + 'serviceKey=' + '3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D' |
| 40 | + '&pageNo=' + '1' | 40 | + '&pageNo=' + '1' |
| 41 | + '&numOfRows=' + '50' | 41 | + '&numOfRows=' + '50' |
| 42 | + '&dataType=' + 'JSON' | 42 | + '&dataType=' + 'JSON' | ... | ... |
| ... | @@ -6,12 +6,25 @@ const festivalSchema = new Schema({ | ... | @@ -6,12 +6,25 @@ const festivalSchema = new Schema({ |
| 6 | addr: String, | 6 | addr: String, |
| 7 | tel: String, | 7 | tel: String, |
| 8 | mapx : Number, | 8 | mapx : Number, |
| 9 | - mapy : Number | 9 | + mapy : Number, |
| 10 | + eventstartdate : String, | ||
| 11 | + eventenddate : String, | ||
| 12 | + overview : String, | ||
| 13 | + firstimage : String, | ||
| 14 | + homepage : String, | ||
| 15 | + district : String, | ||
| 16 | + city : String, | ||
| 17 | + temparature : Number, | ||
| 18 | + weathers : String | ||
| 19 | + // weather : { | ||
| 20 | + // date1: { weather : String, temp : Number}, | ||
| 21 | + // date2: { weather : String, temp : Number}, | ||
| 22 | + // date3: { weather : String, temp : Number}, | ||
| 23 | + // } | ||
| 10 | }, | 24 | }, |
| 11 | { | 25 | { |
| 12 | - timestamps: true | 26 | + versionKey: false |
| 13 | -} | 27 | +}); |
| 14 | -); | ||
| 15 | 28 | ||
| 16 | 29 | ||
| 17 | module.exports = mongoose.model('Festival',festivalSchema); | 30 | module.exports = mongoose.model('Festival',festivalSchema); | ... | ... |
| ... | @@ -2,15 +2,20 @@ const express = require('express'); | ... | @@ -2,15 +2,20 @@ const express = require('express'); |
| 2 | const mongoose = require('mongoose'); | 2 | const mongoose = require('mongoose'); |
| 3 | const db = require('mongodb'); | 3 | const db = require('mongodb'); |
| 4 | const Festival = require('./models/Festival'); | 4 | const Festival = require('./models/Festival'); |
| 5 | +const request = require('request-promise-native'); | ||
| 5 | require("dotenv").config({ path: "variables.env"}); | 6 | require("dotenv").config({ path: "variables.env"}); |
| 6 | 7 | ||
| 7 | -const COORDINATES = require('./coordinates'); | 8 | +const COORDINATES = require('./coordinates')['COORDINATES']; |
| 8 | const DISTRICT = [ | 9 | const DISTRICT = [ |
| 9 | "서울특별시", "부산광역시", "울산광역시", "대구광역시", "대전광역시", | 10 | "서울특별시", "부산광역시", "울산광역시", "대구광역시", "대전광역시", |
| 10 | "인천광역시", "광주광역시", "세종특별자치시", "제주특별자치도", | 11 | "인천광역시", "광주광역시", "세종특별자치시", "제주특별자치도", |
| 11 | "경기도", "강원도", "충청북도", "충청남도", "경상북도", | 12 | "경기도", "강원도", "충청북도", "충청남도", "경상북도", |
| 12 | "경상남도", "전라북도", "전라남도" | 13 | "경상남도", "전라북도", "전라남도" |
| 13 | ] | 14 | ] |
| 15 | +const WEATHERTYPE = [ | ||
| 16 | + '맑음', '비', '비/눈', '눈', '소나기' | ||
| 17 | +]; | ||
| 18 | + | ||
| 14 | function parseDistrict(addr) { | 19 | function parseDistrict(addr) { |
| 15 | const words = addr.split(" "); | 20 | const words = addr.split(" "); |
| 16 | if( DISTRICT.includes(words[0]) ) { | 21 | if( DISTRICT.includes(words[0]) ) { |
| ... | @@ -19,18 +24,18 @@ function parseDistrict(addr) { | ... | @@ -19,18 +24,18 @@ function parseDistrict(addr) { |
| 19 | return []; | 24 | return []; |
| 20 | } | 25 | } |
| 21 | } | 26 | } |
| 27 | +function leftPad(value) { if (value >= 10) { return value; } return `0${value}`; } | ||
| 22 | 28 | ||
| 23 | -let request = require('request-promise-native'); | 29 | +setInterval(() => { |
| 24 | -let options = { | 30 | + //여기에 밑에 애들 들어감 |
| 25 | - 'method': 'GET', | 31 | +}, 86400000); |
| 26 | - 'url' : 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList' | ||
| 27 | - + '?ServiceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D' | ||
| 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 | ||
| 32 | - 'headers': {} | 33 | +var today = new Date(); |
| 33 | -}; | 34 | +var yesterday = new Date(); |
| 35 | +yesterday.setDate(yesterday.getDate() - 1); | ||
| 36 | +let todayString = "" + (today.getFullYear())+leftPad(today.getMonth()+1)+leftPad(today.getDate()); | ||
| 37 | +let yesterdayString = "" + (yesterday.getFullYear())+leftPad(yesterday.getMonth()+1)+leftPad(yesterday.getDate()-1); | ||
| 38 | +var todayTime = leftPad(today.getHours()) + "00"; | ||
| 34 | 39 | ||
| 35 | mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{ | 40 | mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{ |
| 36 | if(err) { | 41 | if(err) { |
| ... | @@ -41,117 +46,126 @@ mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{ | ... | @@ -41,117 +46,126 @@ mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{ |
| 41 | console.log(err + "Reset Failed!"); | 46 | console.log(err + "Reset Failed!"); |
| 42 | } else { | 47 | } else { |
| 43 | console.log(result + "Reset Success!"); | 48 | 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("탈출"); | ||
| 91 | 49 | ||
| 92 | - const newFestival = new Festival(); | 50 | + for(let i = 1; i <= 5; i++) { |
| 93 | - newFestival.title = pinfo['response']['body']['items']['item']['title']; | 51 | + let options = { |
| 94 | - newFestival.addr = pinfo['response']['body']['items']['item']['addr1']; | 52 | + 'method': 'GET', |
| 95 | - newFestival.tel = pinfo['response']['body']['items']['item']['tel']; | 53 | + 'url' : 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList' |
| 96 | - newFestival.mapx = pinfo['response']['body']['items']['item']['mapx']; | 54 | + + '?ServiceKey=' + '3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D' |
| 97 | - newFestival.mapy = pinfo['response']['body']['items']['item']['mapy']; | 55 | + + '&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=C&numOfRows=12' |
| 98 | - newFestival.overview= pinfo['response']['body']['items']['item']['overview']; | 56 | + + '&pageNo='+ i |
| 99 | - newFestival.firstimage = pinfo['response']['body']['items']['item']['firstimage']; | 57 | + + '&_type=json', |
| 100 | - newFestival.homepage = pinfo ['response']['body']['items']['item']['homepage']; | 58 | + |
| 101 | - newFestival.district = distriction[0]; // 광역시/도 | 59 | + 'headers': {} |
| 102 | - newFestival.city = parseDistrict[1]; // 시군구 | 60 | + }; |
| 103 | 61 | ||
| 104 | - await request(Info.detail, function (error, response, body) { | 62 | + request(options, async function (error, response, body) { |
| 63 | + if (error) { | ||
| 64 | + throw new Error(error); | ||
| 65 | + } | ||
| 66 | + let info = JSON.parse(body); | ||
| 67 | + let items = info['response']['body']['items']['item']; | ||
| 68 | + for(item of items) { | ||
| 69 | + let Info = { | ||
| 70 | + 'public': { | ||
| 71 | + 'method': 'GET', | ||
| 72 | + 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?' | ||
| 73 | + + 'ServiceKey=' + '3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D' | ||
| 74 | + + '&contentTypeId=' + '15' | ||
| 75 | + + '&contentId=' + item['contentid'] | ||
| 76 | + + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&defaultYN=Y&firstImageYN=Y&areacodeYN=Y&catcodeYN=Y&addrinfoYN=Y&mapinfoYN=Y&overviewYN=Y&transGuideYN=Y&_type=json', | ||
| 77 | + 'headers': {} | ||
| 78 | + }, | ||
| 79 | + 'detail': { | ||
| 80 | + 'method': 'GET', | ||
| 81 | + 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?' | ||
| 82 | + + 'ServiceKey=' + '3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D' | ||
| 83 | + + '&contentTypeId=' + '15' | ||
| 84 | + + '&contentId=' + item['contentid'] | ||
| 85 | + + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&introYN=Y&_type=json', | ||
| 86 | + 'headers': {} | ||
| 87 | + }, | ||
| 88 | + 'weather': { | ||
| 89 | + 'method': 'GET', | ||
| 90 | + 'url': '', | ||
| 91 | + 'headers': {} | ||
| 92 | + } | ||
| 93 | + }; | ||
| 94 | + await request(Info.public, async function (error, response, body) { | ||
| 105 | if (error) { | 95 | if (error) { |
| 106 | throw new Error(error); | 96 | throw new Error(error); |
| 107 | } | 97 | } |
| 108 | - let dinfo = JSON.parse(body); | ||
| 109 | - newFestival.eventstartdate = dinfo['response']['body']['items']['item']['eventstartdate']; | ||
| 110 | - newFestival.eventenddate = dinfo['response']['body']['items']['item']['eventenddate']; | ||
| 111 | - }); | ||
| 112 | - | ||
| 113 | - // let [nx, ny] = COORDINATES[distriction[0]][distriction[1]]; | ||
| 114 | 98 | ||
| 115 | - // Info.weather.url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst?' | 99 | + let toSave = true; |
| 116 | - // + 'serviceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D' | 100 | + let pinfo = JSON.parse(body); |
| 117 | - // + '&pageNo=' + '1' | 101 | + let distriction = parseDistrict(pinfo['response']['body']['items']['item']['addr1']); |
| 118 | - // + '&numOfRows=' + '50' | 102 | + if (distriction.length == 0) toSave = false; |
| 119 | - // + '&dataType=' + 'JSON' | ||
| 120 | - // + '&base_date=' + '20211129' | ||
| 121 | - // + '&base_time=' + '0500' | ||
| 122 | - // + '&nx=' + nx | ||
| 123 | - // + '&ny=' + ny; | ||
| 124 | 103 | ||
| 125 | - // await request(Info.weather, function (error, response, body) { | 104 | + const newFestival = new Festival(); |
| 126 | - // if (error) { | 105 | + newFestival.title = pinfo['response']['body']['items']['item']['title']; |
| 127 | - // throw new Error(error); | 106 | + newFestival.addr = pinfo['response']['body']['items']['item']['addr1']; |
| 128 | - // } | 107 | + newFestival.tel = pinfo['response']['body']['items']['item']['tel']; |
| 129 | - // let winfo = JSON.parse(body); | 108 | + newFestival.mapx = pinfo['response']['body']['items']['item']['mapx']; |
| 130 | - | 109 | + newFestival.mapy = pinfo['response']['body']['items']['item']['mapy']; |
| 131 | - // for( let item of winfo['response']['body']['items']['item'] ) { | 110 | + newFestival.overview= pinfo['response']['body']['items']['item']['overview']; |
| 132 | - | 111 | + newFestival.firstimage = pinfo['response']['body']['items']['item']['firstimage']; |
| 133 | - // if(item['category']=='TMP') { | 112 | + newFestival.homepage = pinfo ['response']['body']['items']['item']['homepage']; |
| 134 | - // console.log('온도: '+item['fcstValue']); | 113 | + newFestival.district = distriction[0]; // 광역시/도 |
| 135 | - // } else if(item['category']=='PTY') { | 114 | + newFestival.city = distriction[1]; // 시군구 |
| 136 | - // let weather_code = item['fcstValue'] | 115 | + |
| 116 | + await request(Info.detail, function (error, response, body) { | ||
| 117 | + if (error) { | ||
| 118 | + throw new Error(error); | ||
| 119 | + } | ||
| 120 | + let dinfo = JSON.parse(body); | ||
| 121 | + newFestival.eventstartdate = dinfo['response']['body']['items']['item']['eventstartdate']; | ||
| 122 | + newFestival.eventenddate = dinfo['response']['body']['items']['item']['eventenddate']; | ||
| 123 | + | ||
| 124 | + if (newFestival.eventenddate < todayString) toSave = false; | ||
| 125 | + }); | ||
| 126 | + | ||
| 127 | + let [nx, ny] = COORDINATES[distriction[0]][distriction[1]]; | ||
| 128 | + let curDate = ('0500' < todayTime ? todayString : yesterdayString); | ||
| 129 | + | ||
| 130 | + Info.weather.url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst?' | ||
| 131 | + + 'serviceKey=' + '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D' | ||
| 132 | + + '&pageNo=' + '1' | ||
| 133 | + + '&numOfRows=' + '2000' | ||
| 134 | + + '&dataType=' + 'JSON' | ||
| 135 | + + '&base_date=' + '20211129' | ||
| 136 | + + '&base_time=' + '0500' | ||
| 137 | + + '&nx=' + nx | ||
| 138 | + + '&ny=' + ny; | ||
| 139 | + | ||
| 140 | + await request(Info.weather, function (error, response, body) { | ||
| 141 | + if (error) { | ||
| 142 | + throw new Error(error); | ||
| 143 | + } | ||
| 144 | + let winfo = JSON.parse(body); | ||
| 137 | 145 | ||
| 138 | - // if (weather_code == '1'){ console.log('날씨 : 비');} | 146 | + let weathers = {}; |
| 139 | - // else if (weather_code == '2'){ console.log('날씨 :비/눈') ;} | 147 | + for( let item of winfo['response']['body']['items']['item'] ) { |
| 140 | - // else if (weather_code == '3'){ console.log('날씨 :눈') ;} | 148 | + if(item['fcstTime'] === '1200') { // 최고기온 + 날씨 |
| 141 | - // else if (weather_code == '4'){ console.log('날씨 :소나기') ;} | 149 | + let fcstDate = item['fcstDate']; |
| 142 | - // else{console.log('날씨 :맑음') ;} | 150 | + if(!weathers[fcstDate]) weathers[fcstDate] = {}; |
| 143 | - // } | 151 | + if(item['category']=='TMP') { |
| 144 | - // } | 152 | + weathers[fcstDate]['temp'] = item['fcstValue']; |
| 145 | - // }); | 153 | + } else if(item['category']=='PTY') { |
| 154 | + weathers[fcstDate]['weather'] = WEATHERTYPE[item['fcstValue']]; | ||
| 155 | + } | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + newFestival.weathers = JSON.stringify(weathers); | ||
| 159 | + }); | ||
| 146 | 160 | ||
| 147 | - await newFestival.save().then((festival) => { | 161 | + if (toSave) |
| 148 | - console.log(festival, "Save success!"); | 162 | + await newFestival.save().then((festival) => { |
| 149 | - }); | 163 | + console.log(festival, "Save success!"); |
| 150 | - })/*.catch(error => { | 164 | + }); |
| 151 | - console.log(error); | 165 | + }) |
| 152 | - });*/ | 166 | + } |
| 153 | - } | 167 | + }); |
| 154 | - }); | 168 | + } |
| 155 | } | 169 | } |
| 156 | }); | 170 | }); |
| 157 | } | 171 | } | ... | ... |
-
Please register or login to post a comment