ShinSeungMin

Add refreshing and Fix bug

...@@ -141,8 +141,9 @@ app.post('/hook', asyncHandler(async (req, res, next) => { ...@@ -141,8 +141,9 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
141 //날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기 141 //날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기
142 if (moment(message.text, "YYYYMMDD", true).isValid() && MEGA_flag == 3) { 142 if (moment(message.text, "YYYYMMDD", true).isValid() && MEGA_flag == 3) {
143 MEGA_date = parseInt(message.text); 143 MEGA_date = parseInt(message.text);
144 + let today = GettingToday();//오늘 이후인지 확인하기 위해 날짜 가져옴
144 //console.log(MEGA_date, MEGA_TheaterLocation); 145 //console.log(MEGA_date, MEGA_TheaterLocation);
145 - if (MEGA_date && MEGA_TheaterLocationCode) { 146 + if (today<=MEGA_date && MEGA_date && MEGA_TheaterLocationCode) {
146 const text1 = "현재상영작을 가져오는 중입니다."; 147 const text1 = "현재상영작을 가져오는 중입니다.";
147 const text2 = "잠시만 기다려주세요."; 148 const text2 = "잠시만 기다려주세요.";
148 PushMessage(text1, text2); 149 PushMessage(text1, text2);
...@@ -190,16 +191,16 @@ app.post('/hook', asyncHandler(async (req, res, next) => { ...@@ -190,16 +191,16 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
190 PushMessage(PlayingMovie, "바로 링크가 보내집니다."); 191 PushMessage(PlayingMovie, "바로 링크가 보내집니다.");
191 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[0]]; 192 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[0]];
192 setTimeout(function () { 193 setTimeout(function () {
193 - const final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date; 194 + const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
194 - console.log(final_URL) 195 + const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo="+ MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
195 - PushMessage(final_URL, "링크를 누르면 예매창으로 바로 이동합니다."); 196 + PushURLMessage(PC_final_URL, Smartphone_final_URL);
196 - }, 1000);
197 setTimeout(function () { 197 setTimeout(function () {
198 initFlag = false; 198 initFlag = false;
199 MEGA_flag = -1; 199 MEGA_flag = -1;
200 MEGA_PlayingMovieList = []; 200 MEGA_PlayingMovieList = [];
201 PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요."); 201 PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
202 }, 1000); 202 }, 1000);
203 + }, 1000);
203 } else { 204 } else {
204 let index = 0; 205 let index = 0;
205 for (let playingmovie = 0; playingmovie < Object.keys(MEGA_PlayingMovieList).length; playingmovie++) { 206 for (let playingmovie = 0; playingmovie < Object.keys(MEGA_PlayingMovieList).length; playingmovie++) {
...@@ -213,9 +214,10 @@ app.post('/hook', asyncHandler(async (req, res, next) => { ...@@ -213,9 +214,10 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
213 }else if (MEGA_flag == 5) { 214 }else if (MEGA_flag == 5) {
214 const index = parseInt(message.text) - 1; 215 const index = parseInt(message.text) - 1;
215 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]]; 216 MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]];
216 - const final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date; 217 + const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
217 - console.log(final_URL); 218 + const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo="+ MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
218 - PushMessage(final_URL, "링크를 누르면 예매창으로 바로 이동합니다."); 219 + console.log(PC_final_URL, Smartphone_final_URL);
220 + PushURLMessage(PC_final_URL, Smartphone_final_URL);
219 MEGA_PlayingMovieList = []; //영화 리스트 초기화 221 MEGA_PlayingMovieList = []; //영화 리스트 초기화
220 MegaboxKakaoResultTheater = []; 222 MegaboxKakaoResultTheater = [];
221 GetMegaboxKakaoMapURL(MEGA_TheaterLocation); 223 GetMegaboxKakaoMapURL(MEGA_TheaterLocation);
...@@ -250,6 +252,24 @@ try { ...@@ -250,6 +252,24 @@ try {
250 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); 252 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
251 console.log(error); 253 console.log(error);
252 } 254 }
255 +
256 +//오늘 날짜 구하기
257 +function GettingToday(){
258 + var today = new Date();
259 + var year = today.getFullYear();
260 + var month = ('0' + (today.getMonth() + 1)).slice(-2);
261 + var day = ('0' + today.getDate()).slice(-2);
262 + var dateString = year + month + day;
263 + var dateInt = parseInt(dateString);
264 + console.log(dateInt);
265 + return dateInt;
266 +}
267 +
268 +//24시간마다 데이터 초기화
269 +var dayInMilliseconds = 1000 * 60 * 60 * 24;
270 +setInterval(function() { megabox.init(); console.log("success") },dayInMilliseconds );
271 +
272 +//Megabox - Kakao API로 영화관 위치 찾기
253 GetMegaboxKakaoMapURL= async(LOCATE) => { 273 GetMegaboxKakaoMapURL= async(LOCATE) => {
254 let KAKAOOPTION = { 274 let KAKAOOPTION = {
255 url: "https://dapi.kakao.com/v2/local/search/keyword", 275 url: "https://dapi.kakao.com/v2/local/search/keyword",
...@@ -358,3 +378,27 @@ function PushSingleMessage(text1) {//push single message ...@@ -358,3 +378,27 @@ function PushSingleMessage(text1) {//push single message
358 console.log(body) 378 console.log(body)
359 }); 379 });
360 } 380 }
381 +function PushURLMessage(pcurl, smartphoneurl) {//push single message
382 + request.post(
383 + {
384 + url: PUSH_TARGET_URL,
385 + headers: {
386 + 'Authorization': `Bearer ${TOKEN}`
387 + },
388 + json: {
389 + "to": `${USER_ID}`,
390 + "messages": [
391 + {
392 + "type": "text",
393 + "text": "pc버전 url입니다\n\n" + pcurl
394 + },
395 + {
396 + "type": "text",
397 + "text": "mobile버전 url입니다\n\n" + smartphoneurl
398 + }
399 + ]
400 + }
401 + }, (error, response, body) => {
402 + console.log(body)
403 + });
404 +}
...\ No newline at end of file ...\ No newline at end of file
......