이혜인

Adding mobile url, Modifying date part, Init everyday

......@@ -106,7 +106,6 @@ exports.geting_PlayingMovie= async() => {
let n = 0;
console.log(movie_list);
for (item of movie_list) {
console.log(item.getAttribute('form-at'))
movie_data[n++]['running'] = await item.getAttribute('form-at');
}
console.log("Completed get Running");
......
......@@ -138,8 +138,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);
......@@ -149,6 +150,11 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
console.log(MEGA_PlayingMovieURL, megabox.movie_data);
MEGA_flag = 4;
}
else{
const text1 = "영화를 보실 날짜를 다시 입력해주세요.";
const text2 = "ex)20020409";
SendMessage(eventObj, text1, text2);
}
//원본 코드
// MEGA_date = parseInt(eventObj.message.text);
// if (MEGA_date && MEGA_TheaterLocationCode) {
......@@ -175,21 +181,22 @@ app.post('/hook', asyncHandler(async (req, res, next) => {
MEGA_PlayingMovieList[movietitle] = megabox.movie_data[n].movie_num;
}
}
console.log(Object.keys(megabox.movie_data).length);
if (Object.keys(megabox.movie_data).length == 0) {
PushMessage("현재상영작이 없습니다.","영화관 선택 단계로 이동합니다.");
console.log(Object.keys(MEGA_PlayingMovieList).length);
if (Object.keys(MEGA_PlayingMovieList).length == 0) {
PushSingleMessage("현재상영작이 없습니다.\n영화관 선택 단계로 이동합니다.");
setTimeout(function () {
PushMessage("영화관 위치를 입력해주세요", "ex1)강남");
}, 1000);
MEGA_flag = 1;
}else if (Object.keys(MEGA_PlayingMovieList).length == 1) {
PlayingMovie += '1. ' + Object.keys(MEGA_PlayingMovieList)[0];
PlayingMovie += '1: ' + Object.keys(MEGA_PlayingMovieList)[0];
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;
const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo="+ MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
console.log(final_URL)
PushMessage(final_URL, "링크를 누르면 예매창으로 바로 이동합니다.");
PushURLMessage(PC_final_URL, Smartphone_final_URL);
}, 1000);
setTimeout(function () {
initFlag = false;
......@@ -210,9 +217,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);
PushURLMessage(PC_final_URL, Smartphone_final_URL);
setTimeout(function () {
MEGA_PlayingMovieList = [];
initFlag = false;
......@@ -238,6 +246,23 @@ 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 );
//메세지 전송하는 function 모음
function SendMessage(eventObj, text1, text2 = "") { //reply message
request.post(
......@@ -307,3 +332,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)
});
}
......