임승현

Merge branch 'Chatbot' into 'feature/Chatbot_megabox'

Adding mobile url, Modifying date part, Init everyday



See merge request !31
...@@ -106,7 +106,6 @@ exports.geting_PlayingMovie= async() => { ...@@ -106,7 +106,6 @@ exports.geting_PlayingMovie= async() => {
106 let n = 0; 106 let n = 0;
107 console.log(movie_list); 107 console.log(movie_list);
108 for (item of movie_list) { 108 for (item of movie_list) {
109 - console.log(item.getAttribute('form-at'))
110 movie_data[n++]['running'] = await item.getAttribute('form-at'); 109 movie_data[n++]['running'] = await item.getAttribute('form-at');
111 } 110 }
112 console.log("Completed get Running"); 111 console.log("Completed get Running");
......
...@@ -138,8 +138,9 @@ app.post('/hook', asyncHandler(async (req, res, next) => { ...@@ -138,8 +138,9 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
138 //날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기 138 //날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기
139 if (moment(message.text, "YYYYMMDD", true).isValid() && MEGA_flag == 3) { 139 if (moment(message.text, "YYYYMMDD", true).isValid() && MEGA_flag == 3) {
140 MEGA_date = parseInt(message.text); 140 MEGA_date = parseInt(message.text);
141 + let today = GettingToday();//오늘 이후인지 확인하기 위해 날짜 가져옴
141 //console.log(MEGA_date, MEGA_TheaterLocation); 142 //console.log(MEGA_date, MEGA_TheaterLocation);
142 - if (MEGA_date && MEGA_TheaterLocationCode) { 143 + if (today<=MEGA_date && MEGA_date && MEGA_TheaterLocationCode) {
143 const text1 = "현재상영작을 가져오는 중입니다."; 144 const text1 = "현재상영작을 가져오는 중입니다.";
144 const text2 = "잠시만 기다려주세요."; 145 const text2 = "잠시만 기다려주세요.";
145 PushMessage(text1, text2); 146 PushMessage(text1, text2);
...@@ -149,6 +150,11 @@ app.post('/hook', asyncHandler(async (req, res, next) => { ...@@ -149,6 +150,11 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
149 console.log(MEGA_PlayingMovieURL, megabox.movie_data); 150 console.log(MEGA_PlayingMovieURL, megabox.movie_data);
150 MEGA_flag = 4; 151 MEGA_flag = 4;
151 } 152 }
153 + else{
154 + const text1 = "영화를 보실 날짜를 다시 입력해주세요.";
155 + const text2 = "ex)20020409";
156 + SendMessage(eventObj, text1, text2);
157 + }
152 //원본 코드 158 //원본 코드
153 // MEGA_date = parseInt(eventObj.message.text); 159 // MEGA_date = parseInt(eventObj.message.text);
154 // if (MEGA_date && MEGA_TheaterLocationCode) { 160 // if (MEGA_date && MEGA_TheaterLocationCode) {
...@@ -175,21 +181,22 @@ app.post('/hook', asyncHandler(async (req, res, next) => { ...@@ -175,21 +181,22 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
175 MEGA_PlayingMovieList[movietitle] = megabox.movie_data[n].movie_num; 181 MEGA_PlayingMovieList[movietitle] = megabox.movie_data[n].movie_num;
176 } 182 }
177 } 183 }
178 - console.log(Object.keys(megabox.movie_data).length); 184 + console.log(Object.keys(MEGA_PlayingMovieList).length);
179 - if (Object.keys(megabox.movie_data).length == 0) { 185 + if (Object.keys(MEGA_PlayingMovieList).length == 0) {
180 - PushMessage("현재상영작이 없습니다.","영화관 선택 단계로 이동합니다."); 186 + PushSingleMessage("현재상영작이 없습니다.\n영화관 선택 단계로 이동합니다.");
181 setTimeout(function () { 187 setTimeout(function () {
182 PushMessage("영화관 위치를 입력해주세요", "ex1)강남"); 188 PushMessage("영화관 위치를 입력해주세요", "ex1)강남");
183 }, 1000); 189 }, 1000);
184 MEGA_flag = 1; 190 MEGA_flag = 1;
185 }else if (Object.keys(MEGA_PlayingMovieList).length == 1) { 191 }else if (Object.keys(MEGA_PlayingMovieList).length == 1) {
186 - PlayingMovie += '1. ' + Object.keys(MEGA_PlayingMovieList)[0]; 192 + PlayingMovie += '1: ' + Object.keys(MEGA_PlayingMovieList)[0];
187 PushMessage(PlayingMovie, "바로 링크가 보내집니다."); 193 PushMessage(PlayingMovie, "바로 링크가 보내집니다.");
188 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[0]]; 194 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[0]];
189 setTimeout(function () { 195 setTimeout(function () {
190 const final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date; 196 const 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;
191 console.log(final_URL) 198 console.log(final_URL)
192 - PushMessage(final_URL, "링크를 누르면 예매창으로 바로 이동합니다."); 199 + PushURLMessage(PC_final_URL, Smartphone_final_URL);
193 }, 1000); 200 }, 1000);
194 setTimeout(function () { 201 setTimeout(function () {
195 initFlag = false; 202 initFlag = false;
...@@ -210,9 +217,10 @@ app.post('/hook', asyncHandler(async (req, res, next) => { ...@@ -210,9 +217,10 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
210 }else if (MEGA_flag == 5) { 217 }else if (MEGA_flag == 5) {
211 const index = parseInt(message.text) - 1; 218 const index = parseInt(message.text) - 1;
212 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]]; 219 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]];
213 - const final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date; 220 + const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
214 - console.log(final_URL); 221 + const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo="+ MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
215 - PushMessage(final_URL, "링크를 누르면 예매창으로 바로 이동합니다."); 222 + console.log(PC_final_URL);
223 + PushURLMessage(PC_final_URL, Smartphone_final_URL);
216 setTimeout(function () { 224 setTimeout(function () {
217 MEGA_PlayingMovieList = []; 225 MEGA_PlayingMovieList = [];
218 initFlag = false; 226 initFlag = false;
...@@ -238,6 +246,23 @@ try { ...@@ -238,6 +246,23 @@ try {
238 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); 246 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
239 console.log(error); 247 console.log(error);
240 } 248 }
249 +//오늘 날짜 구하기
250 +function GettingToday(){
251 + var today = new Date();
252 + var year = today.getFullYear();
253 + var month = ('0' + (today.getMonth() + 1)).slice(-2);
254 + var day = ('0' + today.getDate()).slice(-2);
255 + var dateString = year + month + day;
256 + var dateInt = parseInt(dateString);
257 + console.log(dateInt);
258 +
259 + return dateInt;
260 +}
261 +
262 +//24시간마다 데이터 초기화
263 +var dayInMilliseconds = 1000 * 60 * 60 * 24;
264 +setInterval(function() { megabox.init(); console.log("success") },dayInMilliseconds );
265 +
241 //메세지 전송하는 function 모음 266 //메세지 전송하는 function 모음
242 function SendMessage(eventObj, text1, text2 = "") { //reply message 267 function SendMessage(eventObj, text1, text2 = "") { //reply message
243 request.post( 268 request.post(
...@@ -306,4 +331,28 @@ function PushSingleMessage(text1) {//push single message ...@@ -306,4 +331,28 @@ function PushSingleMessage(text1) {//push single message
306 }, (error, response, body) => { 331 }, (error, response, body) => {
307 console.log(body) 332 console.log(body)
308 }); 333 });
309 -}
...\ No newline at end of file ...\ No newline at end of file
334 +}
335 +function PushURLMessage(pcurl, smartphoneurl) {//push single message
336 + request.post(
337 + {
338 + url: PUSH_TARGET_URL,
339 + headers: {
340 + 'Authorization': `Bearer ${TOKEN}`
341 + },
342 + json: {
343 + "to": `${USER_ID}`,
344 + "messages": [
345 + {
346 + "type": "text",
347 + "text": "pc버전 url입니다\n\n" + pcurl
348 + },
349 + {
350 + "type": "text",
351 + "text": "mobile버전 url입니다\n\n" + smartphoneurl
352 + }
353 + ]
354 + }
355 + }, (error, response, body) => {
356 + console.log(body)
357 + });
358 +}
......