ShinSeungMin

Add refreshing and Fix bug

......@@ -141,8 +141,9 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
//날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기
if (moment(message.text, "YYYYMMDD", true).isValid() && MEGA_flag == 3) {
MEGA_date = parseInt(message.text);
let today = GettingToday();//오늘 이후인지 확인하기 위해 날짜 가져옴
//console.log(MEGA_date, MEGA_TheaterLocation);
if (MEGA_date && MEGA_TheaterLocationCode) {
if (today<=MEGA_date && MEGA_date && MEGA_TheaterLocationCode) {
const text1 = "현재상영작을 가져오는 중입니다.";
const text2 = "잠시만 기다려주세요.";
PushMessage(text1, text2);
......@@ -190,16 +191,16 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
PushMessage(PlayingMovie, "바로 링크가 보내집니다.");
MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[0]];
setTimeout(function () {
const final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
console.log(final_URL)
PushMessage(final_URL, "링크를 누르면 예매창으로 바로 이동합니다.");
}, 1000);
const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo="+ MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
PushURLMessage(PC_final_URL, Smartphone_final_URL);
setTimeout(function () {
initFlag = false;
MEGA_flag = -1;
MEGA_PlayingMovieList = [];
PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
}, 1000);
}, 1000);
} else {
let index = 0;
for (let playingmovie = 0; playingmovie < Object.keys(MEGA_PlayingMovieList).length; playingmovie++) {
......@@ -213,9 +214,10 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
}else if (MEGA_flag == 5) {
const index = parseInt(message.text) - 1;
MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]];
const final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
console.log(final_URL);
PushMessage(final_URL, "링크를 누르면 예매창으로 바로 이동합니다.");
const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo="+ MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
console.log(PC_final_URL, Smartphone_final_URL);
PushURLMessage(PC_final_URL, Smartphone_final_URL);
MEGA_PlayingMovieList = []; //영화 리스트 초기화
MegaboxKakaoResultTheater = [];
GetMegaboxKakaoMapURL(MEGA_TheaterLocation);
......@@ -250,6 +252,24 @@ try {
console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
console.log(error);
}
//오늘 날짜 구하기
function GettingToday(){
var today = new Date();
var year = today.getFullYear();
var month = ('0' + (today.getMonth() + 1)).slice(-2);
var day = ('0' + today.getDate()).slice(-2);
var dateString = year + month + day;
var dateInt = parseInt(dateString);
console.log(dateInt);
return dateInt;
}
//24시간마다 데이터 초기화
var dayInMilliseconds = 1000 * 60 * 60 * 24;
setInterval(function() { megabox.init(); console.log("success") },dayInMilliseconds );
//Megabox - Kakao API로 영화관 위치 찾기
GetMegaboxKakaoMapURL= async(LOCATE) => {
let KAKAOOPTION = {
url: "https://dapi.kakao.com/v2/local/search/keyword",
......@@ -358,3 +378,27 @@ function PushSingleMessage(text1) {//push single message
console.log(body)
});
}
function PushURLMessage(pcurl, smartphoneurl) {//push single message
request.post(
{
url: PUSH_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": `${USER_ID}`,
"messages": [
{
"type": "text",
"text": "pc버전 url입니다\n\n" + pcurl
},
{
"type": "text",
"text": "mobile버전 url입니다\n\n" + smartphoneurl
}
]
}
}, (error, response, body) => {
console.log(body)
});
}
\ No newline at end of file
......