임승현

Merge branch 'master' into 'feature/Chatbot_megabox'

Add KakaoAPI feature and Add refreshing and Fix bug



See merge request !32
...@@ -17,9 +17,11 @@ var app = express(); ...@@ -17,9 +17,11 @@ var app = express();
17 app.use(bodyParser.json()); 17 app.use(bodyParser.json());
18 ///////////////////////////////////////////////// 18 /////////////////////////////////////////////////
19 // commit 할때 지워야 할것들 19 // commit 할때 지워야 할것들
20 -const USER_ID = '' 20 +const USER_ID = '';
21 -const TOKEN = '' 21 +const TOKEN = '';
22 -const domain = "" 22 +const domain = '';
23 +const KAKAO_KEY = '';
24 +/////////////////////////////////////////////////
23 25
24 let MEGA_date; 26 let MEGA_date;
25 let MEGA_TheaterLocation; 27 let MEGA_TheaterLocation;
...@@ -31,6 +33,7 @@ let initFlag = false; //브랜드 선택 flag ...@@ -31,6 +33,7 @@ let initFlag = false; //브랜드 선택 flag
31 let MEGA_flag = -1; //메가박스 인지 확인하는 flag 33 let MEGA_flag = -1; //메가박스 인지 확인하는 flag
32 let MEGA_count; //메가박스에서 영화관 판단하는 count 34 let MEGA_count; //메가박스에서 영화관 판단하는 count
33 let MEGA_AbleLocationList = []; //메가박스에서 영화관 이름 매치하는 것 저장하는 list 35 let MEGA_AbleLocationList = []; //메가박스에서 영화관 이름 매치하는 것 저장하는 list
36 +let MegaboxKakaoResultTheater = [];
34 exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL; 37 exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL;
35 //////////////////////////////////////////////// 38 ////////////////////////////////////////////////
36 //처음 영화관을 가져오는 것까지 대략 30초가 걸림 => 30초 기다리고 메세지 전송 39 //처음 영화관을 가져오는 것까지 대략 30초가 걸림 => 30초 기다리고 메세지 전송
...@@ -193,16 +196,15 @@ app.post('/hook', asyncHandler(async (req, res, next) => { ...@@ -193,16 +196,15 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
193 PushMessage(PlayingMovie, "바로 링크가 보내집니다."); 196 PushMessage(PlayingMovie, "바로 링크가 보내집니다.");
194 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[0]]; 197 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[0]];
195 setTimeout(function () { 198 setTimeout(function () {
196 - const final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date; 199 + const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
197 const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo="+ MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date; 200 const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo="+ MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
198 - console.log(final_URL)
199 PushURLMessage(PC_final_URL, Smartphone_final_URL); 201 PushURLMessage(PC_final_URL, Smartphone_final_URL);
200 - }, 1000); 202 + setTimeout(function () {
201 - setTimeout(function () { 203 + initFlag = false;
202 - initFlag = false; 204 + MEGA_flag = -1;
203 - MEGA_flag = -1; 205 + MEGA_PlayingMovieList = [];
204 - MEGA_PlayingMovieList = []; 206 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
205 - PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요."); 207 + }, 1000);
206 }, 1000); 208 }, 1000);
207 } else { 209 } else {
208 let index = 0; 210 let index = 0;
...@@ -219,17 +221,26 @@ app.post('/hook', asyncHandler(async (req, res, next) => { ...@@ -219,17 +221,26 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
219 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]]; 221 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]];
220 const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date; 222 const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
221 const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo="+ MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date; 223 const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo="+ MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
222 - console.log(PC_final_URL); 224 + console.log(PC_final_URL, Smartphone_final_URL);
223 PushURLMessage(PC_final_URL, Smartphone_final_URL); 225 PushURLMessage(PC_final_URL, Smartphone_final_URL);
226 + MEGA_PlayingMovieList = []; //영화 리스트 초기화
227 + MegaboxKakaoResultTheater = [];
228 + GetMegaboxKakaoMapURL(MEGA_TheaterLocation);
224 setTimeout(function () { 229 setTimeout(function () {
225 - MEGA_PlayingMovieList = []; 230 + console.log(MegaboxKakaoResultTheater[0]);
226 - initFlag = false; 231 + let MegaboxKakaoResultTheaterNAME = MegaboxKakaoResultTheater[0]['theater_name'];
227 - MEGA_flag = -1; 232 + let MegaboxKakaoResultTheaterURL = MegaboxKakaoResultTheater[0]['theater_url'];
228 - PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요."); 233 + console.log(MegaboxKakaoResultTheaterNAME, MegaboxKakaoResultTheaterURL);
229 - }, 1000); 234 + PushMessage(MegaboxKakaoResultTheaterURL, "카카오맵으로 검색한 " + MegaboxKakaoResultTheaterNAME+ "의 위치입니다.");
235 + setTimeout(function () {
236 + //EGA_PlayingMovieList = [];
237 + initFlag = false;
238 + MEGA_flag = -1;
239 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
240 + }, 1000);
241 + }, 2000);
230 } 242 }
231 } 243 }
232 -
233 res.sendStatus(200); 244 res.sendStatus(200);
234 })) 245 }))
235 //}); 246 //});
...@@ -255,7 +266,6 @@ function GettingToday(){ ...@@ -255,7 +266,6 @@ function GettingToday(){
255 var dateString = year + month + day; 266 var dateString = year + month + day;
256 var dateInt = parseInt(dateString); 267 var dateInt = parseInt(dateString);
257 console.log(dateInt); 268 console.log(dateInt);
258 -
259 return dateInt; 269 return dateInt;
260 } 270 }
261 271
...@@ -263,6 +273,46 @@ function GettingToday(){ ...@@ -263,6 +273,46 @@ function GettingToday(){
263 var dayInMilliseconds = 1000 * 60 * 60 * 24; 273 var dayInMilliseconds = 1000 * 60 * 60 * 24;
264 setInterval(function() { megabox.init(); console.log("success") },dayInMilliseconds ); 274 setInterval(function() { megabox.init(); console.log("success") },dayInMilliseconds );
265 275
276 +//Megabox - Kakao API로 영화관 위치 찾기
277 +GetMegaboxKakaoMapURL= async(LOCATE) => {
278 + let KAKAOOPTION = {
279 + url: "https://dapi.kakao.com/v2/local/search/keyword",
280 + method: "GET",
281 + headers: {
282 + 'Authorization': `KakaoAK ${KAKAO_KEY}` // commit 할때 지워야 할것
283 + },
284 + qs: {
285 + 'query': '메가박스 ' + LOCATE, // 메가박스 영화관이름
286 + //'category_group_code' : 'CT1',
287 + 'size': 5
288 + },
289 + encoding: 'UTF-8'
290 + };
291 + let selectable_theaters = [];
292 + request(KAKAOOPTION, function (err, res, body) {
293 + info_list = JSON.parse(body).documents;
294 +
295 + if (!err && res.statusCode == 200) {
296 + info_list.forEach(info => {
297 + //console.log(info.category_name);
298 + if (info.category_name.endsWith("메가박스")) {
299 + const theater_info = {
300 + "theater_name": info.place_name,
301 + "theater_url": info.place_url
302 + };
303 + //console.log(theater_info);
304 + //return theater_info;
305 + selectable_theaters.push(theater_info);
306 + }
307 + });
308 + }
309 + console.log(selectable_theaters);
310 + MegaboxKakaoResultTheater = selectable_theaters;
311 + return;
312 + });
313 +
314 +}
315 +
266 //메세지 전송하는 function 모음 316 //메세지 전송하는 function 모음
267 function SendMessage(eventObj, text1, text2 = "") { //reply message 317 function SendMessage(eventObj, text1, text2 = "") { //reply message
268 request.post( 318 request.post(
......
This diff could not be displayed because it is too large.
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
16 "chromedriver": "^101.0.0", 16 "chromedriver": "^101.0.0",
17 "express": "^4.18.1", 17 "express": "^4.18.1",
18 "express-async-handler": "^1.2.0", 18 "express-async-handler": "^1.2.0",
19 + "moment": "^2.29.3",
19 "puppeteer": "^14.1.1", 20 "puppeteer": "^14.1.1",
21 + "request": "^2.88.2",
20 "selenium-webdriver": "^4.1.2" 22 "selenium-webdriver": "^4.1.2"
21 } 23 }
22 } 24 }
......