이혜인

modify getting playingmovielist

1 const chatbot = require("./app.js"); 1 const chatbot = require("./app.js");
2 -
3 const request = require('request'); 2 const request = require('request');
4 const cheerio = require('cheerio'); 3 const cheerio = require('cheerio');
5 const puppeteer = require('puppeteer'); 4 const puppeteer = require('puppeteer');
6 -
7 require('chromedriver'); 5 require('chromedriver');
8 const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기 6 const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기
9 var webdriver = require('selenium-webdriver'); 7 var webdriver = require('selenium-webdriver');
10 var By = webdriver.By; 8 var By = webdriver.By;
11 const chrome = require('selenium-webdriver/chrome');//크롬 사용시 9 const chrome = require('selenium-webdriver/chrome');//크롬 사용시
12 -
13 const async = require('async') 10 const async = require('async')
14 let express = require('express'); 11 let express = require('express');
15 let app = express(); 12 let app = express();
...@@ -17,27 +14,20 @@ let bodyParser = require('body-parser'); ...@@ -17,27 +14,20 @@ let bodyParser = require('body-parser');
17 const { timeout } = require('async'); 14 const { timeout } = require('async');
18 app.use(bodyParser.urlencoded({ extended: false })); 15 app.use(bodyParser.urlencoded({ extended: false }));
19 app.use(bodyParser.json()); 16 app.use(bodyParser.json());
20 -
21 -
22 const booking_url = "https://megabox.co.kr/booking?"; 17 const booking_url = "https://megabox.co.kr/booking?";
23 exports.booking_url = booking_url; 18 exports.booking_url = booking_url;
24 const rate_url = "https://www.megabox.co.kr/movie"; 19 const rate_url = "https://www.megabox.co.kr/movie";
25 -
26 let r =0; 20 let r =0;
27 let movie_data = []; 21 let movie_data = [];
28 exports.movie_data = movie_data; 22 exports.movie_data = movie_data;
29 let location_data = []; 23 let location_data = [];
30 exports.location_data = location_data; 24 exports.location_data = location_data;
31 let index = 0; 25 let index = 0;
32 -
33 -
34 exports.init = ()=>{async.waterfall([//for 동기적 처리 26 exports.init = ()=>{async.waterfall([//for 동기적 처리
35 async () => { 27 async () => {
36 -
37 const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();// 28 const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();//
38 driver.get(booking_url); 29 driver.get(booking_url);
39 driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 30 driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴
40 -
41 let seoul = await driver.wait(until.elementsLocated(By.css('#mCSB_4_container>ul>li>#btn'))); 31 let seoul = await driver.wait(until.elementsLocated(By.css('#mCSB_4_container>ul>li>#btn')));
42 let Gyeonggi = await driver.wait(until.elementsLocated(By.css('#mCSB_5_container>ul>li>#btn'))); 32 let Gyeonggi = await driver.wait(until.elementsLocated(By.css('#mCSB_5_container>ul>li>#btn')));
43 const Incheon = await driver.wait(until.elementsLocated(By.css('#mCSB_6_container>ul>li>#btn'))); 33 const Incheon = await driver.wait(until.elementsLocated(By.css('#mCSB_6_container>ul>li>#btn')));
...@@ -50,7 +40,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 ...@@ -50,7 +40,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
50 for (item of location_list[i]) { 40 for (item of location_list[i]) {
51 location_data[index++] = { 41 location_data[index++] = {
52 'LocationName':await item.getAttribute("brch-nm"), 42 'LocationName':await item.getAttribute("brch-nm"),
53 - 'LocationNUm' : await item.getAttribute("brch-no") 43 + 'LocationNum' : await item.getAttribute("brch-no")
54 } 44 }
55 // let location_name = await item.getAttribute("brch-nm"); 45 // let location_name = await item.getAttribute("brch-nm");
56 // let location_num = await item.getAttribute("brch-no"); 46 // let location_num = await item.getAttribute("brch-no");
...@@ -59,14 +49,12 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 ...@@ -59,14 +49,12 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
59 // location_data[index++] = obj; 49 // location_data[index++] = obj;
60 } 50 }
61 } 51 }
62 -
63 let movie_list = await driver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); 52 let movie_list = await driver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
64 r = 0; 53 r = 0;
65 for (item of movie_list) { 54 for (item of movie_list) {
66 //Using getAttribute to get the data 55 //Using getAttribute to get the data
67 movie_data[r++] = { 56 movie_data[r++] = {
68 'rank' : r, 57 'rank' : r,
69 -
70 'title' : await item.getAttribute("movie-nm"), 58 'title' : await item.getAttribute("movie-nm"),
71 'movie_num':await item.getAttribute("movie-no"), 59 'movie_num':await item.getAttribute("movie-no"),
72 } 60 }
...@@ -75,9 +63,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 ...@@ -75,9 +63,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
75 driver.close(); 63 driver.close();
76 64
77 }, 65 },
78 -
79 async () => { 66 async () => {
80 -
81 r = 0; 67 r = 0;
82 const browser = await puppeteer.launch({ 68 const browser = await puppeteer.launch({
83 headless: true 69 headless: true
...@@ -101,16 +87,16 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 ...@@ -101,16 +87,16 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
101 movie_data[r++]['rate'] = '예매율 0%'; 87 movie_data[r++]['rate'] = '예매율 0%';
102 } 88 }
103 } 89 }
104 - console.log("completed") 90 +
105 browser.close(); 91 browser.close();
92 + console.log("Comepleted!");
106 }, 93 },
107 94
108 ])} 95 ])}
109 96
110 - 97 +let appdriver;
111 -const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
112 -
113 exports.using_PlayingMovieURL = async(PlayingMovieURL) => { 98 exports.using_PlayingMovieURL = async(PlayingMovieURL) => {
99 + appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
114 appdriver.get(PlayingMovieURL); 100 appdriver.get(PlayingMovieURL);
115 //appdriver.switchTo().frame(0) 101 //appdriver.switchTo().frame(0)
116 //frameBokdMBooking 프레임 가져옴 102 //frameBokdMBooking 프레임 가져옴
...@@ -118,24 +104,12 @@ exports.using_PlayingMovieURL = async(PlayingMovieURL) => { ...@@ -118,24 +104,12 @@ exports.using_PlayingMovieURL = async(PlayingMovieURL) => {
118 exports.geting_PlayingMovie= async() => { 104 exports.geting_PlayingMovie= async() => {
119 let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); 105 let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
120 let n = 0; 106 let n = 0;
107 + console.log(movie_list);
121 for (item of movie_list) { 108 for (item of movie_list) {
122 - movie_data[n++]['running'] = await item.getAttribute('form-at') 109 + console.log(item.getAttribute('form-at'))
110 + movie_data[n++]['running'] = await item.getAttribute('form-at');
123 } 111 }
124 - console.log("completed") 112 + console.log("Completed get Running");
125 -
126 } 113 }
127 114
128 -app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 여부 객체에 넣음
129 -
130 - // let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
131 - // let n = 0;
132 - // for (item of movie_list) {
133 - // movie_data[n++]['running'] = await item.getAttribute('form-at')
134 - // }
135 - using_PlayingMovieURL('https://megabox.co.kr/booking?brchNo1=4451&playDe=20220606');
136 - geting_PlayingMovie();
137 -
138 - res.send(PlayingMovieList);
139 -})
140 -
141 -app.listen(8000);
...\ No newline at end of file ...\ No newline at end of file
115 +app.listen(5000);
...\ No newline at end of file ...\ No newline at end of file
......
1 -let megabox = require('./Megabox.js'); 1 +const megabox = require('./Megabox.js');
2 -const async = require('async') 2 +//const SearchingTheaterAPI = require('./SearchingTheaterAPI');
3 -//let SearchingTheaterAPI = require('./SearchingTheaterAPI'); 3 +const async = require('async');
4 - 4 +megabox.init(); //메가박스 코드 시작(영화관 리스트 가져오기)
5 -megabox.init();
6 -
7 -const request = require('request');
8 -var express = require('express');
9 const PUSH_TARGET_URL = 'https://api.line.me/v2/bot/message/push' 5 const PUSH_TARGET_URL = 'https://api.line.me/v2/bot/message/push'
10 -const USER_ID = ''
11 -
12 const REPLY_TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 6 const REPLY_TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
13 -const TOKEN = '' 7 +const asyncHandler = require('express-async-handler')
14 -const fs = require('fs'); 8 +const bodyParser = require('body-parser');
15 -const path = require('path'); 9 +const request = require('request');
10 +const moment = require("moment");
16 const HTTPS = require('https'); 11 const HTTPS = require('https');
17 -const domain = "" 12 +const path = require('path');
13 +const fs = require('fs');
18 const sslport = 23023; 14 const sslport = 23023;
19 -const bodyParser = require('body-parser'); 15 +var express = require('express');
20 var app = express(); 16 var app = express();
21 app.use(bodyParser.json()); 17 app.use(bodyParser.json());
22 - 18 +/////////////////////////////////////////////////
23 -const moment = require("moment"); 19 +// commit 할때 지워야 할것들
20 +const USER_ID = ''
21 +const TOKEN = ''
22 +const domain = ""
24 23
25 let MEGA_date; 24 let MEGA_date;
26 let MEGA_TheaterLocation; 25 let MEGA_TheaterLocation;
26 +let MEGA_TheaterLocationCode;
27 let MEGA_PlayingMovieList = []; 27 let MEGA_PlayingMovieList = [];
28 let MEGA_title; 28 let MEGA_title;
29 let MEGA_PlayingMovieURL; 29 let MEGA_PlayingMovieURL;
30 +let initFlag = false; //브랜드 선택 flag
31 +let MEGA_flag = -1; //메가박스 인지 확인하는 flag
32 +let MEGA_count; //메가박스에서 영화관 판단하는 count
33 +let MEGA_AbleLocationList = []; //메가박스에서 영화관 이름 매치하는 것 저장하는 list
30 exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL; 34 exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL;
35 +////////////////////////////////////////////////
36 +//처음 영화관을 가져오는 것까지 대략 30초가 걸림 => 30초 기다리고 메세지 전송
31 37
32 -let MEGA_flag = 0; 38 +setTimeout(function () {
33 - 39 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
34 - 40 +}, 30000);
35 -function SendMessage(eventObj, text1, text2 = ""){
36 - request.post(
37 - {
38 - url: REPLY_TARGET_URL,
39 - headers: {
40 - 'Authorization': `Bearer ${TOKEN}`
41 - },
42 - json: {
43 - "replyToken":eventObj.replyToken,
44 - "messages":[
45 - {
46 - "type":"text",
47 - "text":text1
48 - },
49 - {
50 - "type":"text",
51 - "text":text2
52 - }
53 - ]
54 - }
55 -
56 - },(error, response, body) => {
57 - console.log(body);
58 - });
59 -}
60 -function PushMessage(eventObj, text1, text2 = ""){
61 -request.post(
62 - {
63 - url: PUSH_TARGET_URL,
64 - headers: {
65 - 'Authorization': `Bearer ${TOKEN}`
66 - },
67 - json: {
68 - "to": `${USER_ID}`,
69 - "messages":[
70 - {
71 - "type":"text",
72 - "text":text1
73 - },
74 - {
75 - "type":"text",
76 - "text":text2
77 - }
78 - ]
79 - }
80 - },(error, response, body) => {
81 - console.log(body)
82 - });
83 -}
84 -
85 -function PusbuttonhMessage(final_URL){
86 - request.post(
87 - {
88 - url: PUSH_TARGET_URL,
89 - headers: {
90 - 'Authorization': `Bearer ${TOKEN}`
91 - },
92 - json:
93 -
94 - { "to": `${USER_ID}`,
95 - "type": "template",
96 - "altText": "this is a carousel template",
97 - "template": {
98 - "type": "carousel",
99 - "columns": [
100 - {
101 - "thumbnailImageUrl": "https://megabox.co.kr/SharedImg/2022/05/16/WApIttC9CrStYU7j7jzFRlc2HsIXBQtY_150.jpg",
102 - "imageBackgroundColor": "#FFFFFF",
103 - "title": "this is menu",
104 - "text": "description",
105 - "defaultAction": {
106 - "type": "uri",
107 - "label": "View detail",
108 - "uri": "https://megabox.co.kr/"
109 - },
110 - "actions": [
111 - {
112 - "type":"message",
113 - "label":"Yes",
114 - "text":"Yes"
115 - },
116 - {
117 - "type":"message",
118 - "label":"Yes",
119 - "text":"Yes"
120 - },
121 - {
122 - "type": "uri",
123 - "label": "View detail",
124 - "uri": "https://megabox.co.kr/"
125 - }
126 - ]
127 - },
128 -
129 - {
130 - "thumbnailImageUrl": "https://example.com/bot/images/item2.jpg",
131 - "imageBackgroundColor": "#000000",
132 - "title": "this is menu",
133 - "text": "description",
134 - "defaultAction": {
135 - "type": "uri",
136 - "label": "View detail",
137 - "uri": "http://example.com/page/222"
138 - },
139 - "actions": [
140 - {
141 - "type":"message",
142 - "label":"Yes",
143 - "text":"Yes"
144 -
145 - },
146 - {
147 - "type":"message",
148 - "label":"Yes",
149 - "text":"Yes"
150 -
151 - },
152 - {
153 - "type": "uri",
154 - "label": "View detail",
155 - "uri": "https://megabox.co.kr/"
156 - }
157 - ]
158 - }
159 - ],
160 - "imageAspectRatio": "rectangle",
161 - "imageSize": "cover"
162 - }
163 - }
164 - // {
165 - // "type": "template",
166 - // //"altText": "This is a buttons template",
167 - // "template": {
168 - // "type": "buttons",
169 - // "thumbnailImageUrl": "https://megabox.co.kr/SharedImg/2022/05/16/WApIttC9CrStYU7j7jzFRlc2HsIXBQtY_150.jpg",
170 - // "imageAspectRatio": "rectangle",
171 - // "imageSize": "cover",
172 - // "imageBackgroundColor": "#FFFFFF",
173 - // "title": "Menu",
174 - // "text": "Please select",
175 - // "actions": [
176 - // {
177 - // "type": "message",
178 - // "label": "Yes",
179 - // "text": "yes"
180 - // },
181 - // {
182 - // "type": "uri",
183 - // "label": "View detail",
184 - // "uri": final_URL
185 - // }
186 - // ]
187 - // }
188 - //}
189 - }
190 - )}
191 -
192 -app.post('/hook', (req, res) => {
193 41
42 +//app.post('/hook', function (req, res) {
43 +app.post('/hook', asyncHandler(async (req, res, next) => {
194 var eventObj = req.body.events[0]; 44 var eventObj = req.body.events[0];
195 var source = eventObj.source; 45 var source = eventObj.source;
196 var message = eventObj.message; 46 var message = eventObj.message;
197 -
198 // request log 47 // request log
199 - console.log('======================', new Date() ,'======================'); 48 + console.log('======================', new Date(), '======================');
200 console.log('[request]', req.body); 49 console.log('[request]', req.body);
201 console.log('[request source] ', eventObj.source); 50 console.log('[request source] ', eventObj.source);
202 console.log('[request message]', eventObj.message); 51 console.log('[request message]', eventObj.message);
203 - 52 + //어느 순간에서든 "브랜드"를 입력해 원하는 브랜드 선택
204 - 53 + //initFlag : false ==> 브랜드 선택 전
205 - if(eventObj.message.text == 3 && MEGA_flag === 0){ 54 + //initFlag : true ==> 브랜드 선택 됨
55 + if (eventObj.message.text == "브랜드") {
56 + initFlag = false;
57 + MEGA_flag = -1;
58 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
59 + }
60 + //브랜드 선택- 메가박스 인 경우 MEGA_flag를 0으로 두어 메가박스 임을 확인
61 + if (initFlag == false && eventObj.message.text == 3) {
62 + initFlag = true;
63 + MEGA_flag = 0;
64 + }
65 + //메가박스로 브랜드 선택된 경우
66 + if (initFlag == true && MEGA_flag != -1) {
67 + if (MEGA_flag == 0) {
206 const text1 = "영화관 위치를 입력해주세요"; 68 const text1 = "영화관 위치를 입력해주세요";
207 const text2 = "ex1)강남"; 69 const text2 = "ex1)강남";
208 SendMessage(eventObj, text1, text2); 70 SendMessage(eventObj, text1, text2);
209 MEGA_flag++; 71 MEGA_flag++;
210 - PusbuttonhMessage("https://developers.line.biz/en/reference/messaging-api/#message-common-properties"); 72 + //PusbuttonhMessage("https://developers.line.biz/en/reference/messaging-api/#message-common-properties");
211 - console.log(MEGA_flag) 73 + //console.log(MEGA_flag)
74 + }else if (MEGA_flag === 1) {
75 + MEGA_count = 0; //MEGA_count 초기화
76 + MEGA_AbleLocationList.length = 0; //MEGA_AbleLocationList 초기화
77 + for (i of megabox.location_data) {
78 + if (i['LocationName'].includes(message.text)) {
79 + MEGA_AbleLocationList[MEGA_count++] = i;
80 + }
212 } 81 }
213 82
214 - if(MEGA_flag===1){ 83 + if (MEGA_count == 1) { //결과 1개 => 바로 다음 단계 넘어가기
215 - console.log(MEGA_flag); 84 + MEGA_TheaterLocation = MEGA_AbleLocationList[0].LocationName;
216 - for(i of megabox.location_data){ 85 + MEGA_TheaterLocationCode = MEGA_AbleLocationList[0].LocationNum;
217 - if(i['LocationName'] === message.text){ 86 + console.log(MEGA_TheaterLocation, MEGA_TheaterLocationCode);
218 - MEGA_TheaterLocation = i['LocationNUm'];
219 - console.log(MEGA_TheaterLocation);
220 MEGA_flag++; 87 MEGA_flag++;
221 - console.log(MEGA_flag) 88 + } else if (MEGA_count > 1) { //결과 2개 이상 => 리스트 출력해주고 번호로 입력받아 넘어가기
222 - break; 89 + console.log(MEGA_AbleLocationList[0], MEGA_AbleLocationList[1]);
90 + let MEGA_OutputString = "원하시는 상영관의 번호를 정확히 입력해주세요\n"; //메가박스 영화관 가능 정보 string
91 + //PushSingleMessage("원하시는 상영관의 번호를 정확히 입력해주세요");
92 + for (let x = 0; x < MEGA_count; x++) {
93 + //PushSingleMessage(String(x + 1) + ": " + MEGA_AbleLocationList[x].LocationName);
94 + MEGA_OutputString += String(x + 1) + ": " + MEGA_AbleLocationList[x].LocationName + "\n";
95 + console.log(String(x + 1), MEGA_AbleLocationList[x].LocationName);
96 + }
97 + MEGA_OutputString += String(MEGA_count + 1) + ": 다시 검색하기";
98 + PushSingleMessage(MEGA_OutputString);
99 + MEGA_flag = 101;
100 + } else {
101 + PushSingleMessage("다시 입력해주세요.");
223 } 102 }
103 + //원본 코드
104 + //console.log(MEGA_flag);
105 + // for (i of megabox.location_data) {
106 + // if (i['LocationName'] === message.text) {
107 + // MEGA_TheaterLocationCode = i['LocationNUm'];
108 + // console.log(MEGA_TheaterLocationCode);
109 + // MEGA_flag++;
110 + // console.log(MEGA_flag)
111 + // break;
112 + // }
113 + // }
114 + } else if (MEGA_flag == 101) {
115 + // 0< input || input > MEGA_count+1 : 다시 검색
116 + let tempNum = parseInt(message.text);
117 + if (tempNum > 0 && tempNum < MEGA_count + 1) {
118 + //번호에 맞는 LocationCode 전달
119 + MEGA_TheaterLocation = MEGA_AbleLocationList[tempNum - 1].LocationName;
120 + MEGA_TheaterLocationCode = MEGA_AbleLocationList[tempNum - 1].LocationNum;
121 + console.log(MEGA_TheaterLocation, MEGA_TheaterLocationCode);
122 + MEGA_flag = 2;
123 + } else {
124 + //다시 장소 입력받기
125 + const text1 = "영화관 위치를 입력해주세요";
126 + const text2 = "ex1)강남";
127 + SendMessage(eventObj, text1, text2);
128 + MEGA_flag = 1;
224 } 129 }
225 } 130 }
226 - 131 + //날짜 입력 받기
227 - if(MEGA_flag === 2){ 132 + if (MEGA_flag == 2) {
228 - const text1 = "영화를 보실 날짜를 입력해주세요."; 133 + const text1 = "현재 영화관은 " + MEGA_TheaterLocation + " 입니다.\n영화를 보실 날짜를 입력해주세요.";
229 const text2 = "ex)20020409"; 134 const text2 = "ex)20020409";
230 SendMessage(eventObj, text1, text2); 135 SendMessage(eventObj, text1, text2);
231 - ++MEGA_flag; 136 + MEGA_flag = 3;
232 } 137 }
233 - 138 + //날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기
234 - if(moment(eventObj.message.text, "YYYYMMDD", true).isValid() && MEGA_flag===3){ 139 + if (moment(message.text, "YYYYMMDD", true).isValid() && MEGA_flag == 3) {
235 - 140 + MEGA_date = parseInt(message.text);
236 - MEGA_date = parseInt(eventObj.message.text); 141 + //console.log(MEGA_date, MEGA_TheaterLocation);
237 - 142 + if (MEGA_date && MEGA_TheaterLocationCode) {
238 - if(MEGA_date && MEGA_TheaterLocation){ 143 + const text1 = "현재상영작을 가져오는 중입니다.";
239 - MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1='+MEGA_TheaterLocation+'&playDe='+MEGA_date; 144 + const text2 = "잠시만 기다려주세요.";
240 - console.log(MEGA_PlayingMovieURL) 145 + PushMessage(text1, text2);
241 - async.waterfall[ 146 + MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1=' + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
242 - megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL), 147 + megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL);
243 - megabox.geting_PlayingMovie() 148 + await megabox.geting_PlayingMovie();
244 - ] 149 + console.log(MEGA_PlayingMovieURL, megabox.movie_data);
245 - MEGA_flag++ 150 + MEGA_flag = 4;
246 - console.log(MEGA_flag);
247 } 151 }
152 + //원본 코드
153 + // MEGA_date = parseInt(eventObj.message.text);
154 + // if (MEGA_date && MEGA_TheaterLocationCode) {
155 + // MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1=' + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
156 + // console.log(MEGA_PlayingMovieURL)
157 + // async.waterfall[
158 + // megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL),
159 + // megabox.geting_PlayingMovie()
160 + // ]
161 + // MEGA_flag++
162 + // console.log(MEGA_flag);
163 + // }
248 } 164 }
249 - 165 + if (MEGA_flag == 4) {
250 - if(MEGA_flag===4){
251 -
252 let obj = {}; 166 let obj = {};
253 let n; 167 let n;
254 let PlayingMovie = "-현재 상영작-\n\n"; 168 let PlayingMovie = "-현재 상영작-\n\n";
255 - const text1 = "현재상영작을 가져오는 중입니다.";
256 - const text2 = "잠시만 기다려주세요.";
257 - PushMessage(eventObj, text1, text2);
258 - setTimeout(function() {
259 let movietitle; 169 let movietitle;
260 console.log(megabox.movie_data); 170 console.log(megabox.movie_data);
261 - for(n = 0; n<Object.keys(megabox.movie_data).length; n++){ 171 + for (n = 0; n < Object.keys(megabox.movie_data).length; n++) {
262 - if(megabox.movie_data[n].running==='Y'){ 172 + if (megabox.movie_data[n].running == 'Y') {
263 console.log(megabox.movie_data[n]); 173 console.log(megabox.movie_data[n]);
264 movietitle = megabox.movie_data[n].title; 174 movietitle = megabox.movie_data[n].title;
265 MEGA_PlayingMovieList[movietitle] = megabox.movie_data[n].movie_num; 175 MEGA_PlayingMovieList[movietitle] = megabox.movie_data[n].movie_num;
266 } 176 }
267 } 177 }
268 - console.log(MEGA_PlayingMovieList); 178 + console.log(Object.keys(megabox.movie_data).length);
269 - 179 + if (Object.keys(megabox.movie_data).length == 0) {
270 - if(MEGA_PlayingMovieList.length == 0){ 180 + PushMessage("현재상영작이 없습니다.","영화관 선택 단계로 이동합니다.");
271 - SendMessage(eventObj, "현재상영작이 없습니다.",""); 181 + setTimeout(function () {
272 - } 182 + PushMessage("영화관 위치를 입력해주세요", "ex1)강남");
273 - else if(MEGA_PlayingMovieList.length == 1){ 183 + }, 1000);
274 - SendMessage(eventObj, MEGA_PlayingMovieList[0],""); 184 + MEGA_flag = 1;
275 - } 185 + }else if (Object.keys(MEGA_PlayingMovieList).length == 1) {
276 - else{ 186 + PlayingMovie += '1. ' + Object.keys(MEGA_PlayingMovieList)[0];
187 + PushMessage(PlayingMovie, "바로 링크가 보내집니다.");
188 + MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[0]];
189 + setTimeout(function () {
190 + const final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
191 + console.log(final_URL)
192 + PushMessage(final_URL, "링크를 누르면 예매창으로 바로 이동합니다.");
193 + }, 1000);
194 + setTimeout(function () {
195 + initFlag = false;
196 + MEGA_flag = -1;
197 + MEGA_PlayingMovieList = [];
198 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
199 + }, 1000);
200 + } else {
277 let index = 0; 201 let index = 0;
278 - for(let playingmovie = 0; playingmovie < Object.keys(MEGA_PlayingMovieList).length; playingmovie++) 202 + for (let playingmovie = 0; playingmovie < Object.keys(MEGA_PlayingMovieList).length; playingmovie++) {
279 - { 203 + PlayingMovie += (playingmovie + 1).toString() + '. ' + Object.keys(MEGA_PlayingMovieList)[index++];
280 - PlayingMovie += (playingmovie+1).toString()+'. ' + Object.keys(MEGA_PlayingMovieList)[index++]; 204 + PlayingMovie += "\n";
281 - PlayingMovie +="\n";
282 } 205 }
283 -
284 console.log(PlayingMovie); 206 console.log(PlayingMovie);
285 - PushMessage(eventObj, PlayingMovie, "예매할 영화 번호를 입력해주세요.\n ex)1 (영화 앞 숫자만 입력)"); 207 + await PushMessage(PlayingMovie, "예매할 영화 번호를 입력해주세요.\n ex)1 (영화 앞 숫자만 입력)");
208 + MEGA_flag = 5;
286 } 209 }
287 - 210 + }else if (MEGA_flag == 5) {
288 - MEGA_flag++; 211 + const index = parseInt(message.text) - 1;
289 - },10000); 212 + MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]];
290 - 213 + const final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
214 + console.log(final_URL);
215 + PushMessage(final_URL, "링크를 누르면 예매창으로 바로 이동합니다.");
216 + setTimeout(function () {
217 + MEGA_PlayingMovieList = [];
218 + initFlag = false;
219 + MEGA_flag = -1;
220 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
221 + }, 1000);
291 } 222 }
292 - if(MEGA_flag===5){
293 - const index = parseInt(message.text) -1;
294 - MEGA_title= MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]]
295 - const final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo="+ MEGA_title+"&brchNo1="+MEGA_TheaterLocation+'&playDe='+MEGA_date;
296 - console.log(final_URL)
297 -
298 - PushMessage(eventObj, final_URL, "예매창으로 바로 이동합니다.");
299 -
300 -
301 -
302 } 223 }
303 224
304 res.sendStatus(200); 225 res.sendStatus(200);
305 - 226 +}))
306 -}); 227 +//});
307 -
308 try { 228 try {
309 const option = { 229 const option = {
310 - ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), 230 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'),
311 - key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), 231 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(),
312 - cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), 232 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(),
313 }; 233 };
314 -
315 HTTPS.createServer(option, app).listen(sslport, () => { 234 HTTPS.createServer(option, app).listen(sslport, () => {
316 console.log(`[HTTPS] Server is started on port ${sslport}`); 235 console.log(`[HTTPS] Server is started on port ${sslport}`);
317 }); 236 });
318 - } catch (error) { 237 +} catch (error) {
319 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); 238 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
320 console.log(error); 239 console.log(error);
240 +}
241 +//메세지 전송하는 function 모음
242 +function SendMessage(eventObj, text1, text2 = "") { //reply message
243 + request.post(
244 + {
245 + url: REPLY_TARGET_URL,
246 + headers: {
247 + 'Authorization': `Bearer ${TOKEN}`
248 + },
249 + json: {
250 + "replyToken": eventObj.replyToken,
251 + "messages": [
252 + {
253 + "type": "text",
254 + "text": text1
255 + },
256 + {
257 + "type": "text",
258 + "text": text2
321 } 259 }
322 - 260 + ]
323 - 261 + }
324 - 262 + }, (error, response, body) => {
263 + console.log(body);
264 + });
265 +}
266 +function PushMessage(text1, text2 = "") { //push two message
267 + request.post(
268 + {
269 + url: PUSH_TARGET_URL,
270 + headers: {
271 + 'Authorization': `Bearer ${TOKEN}`
272 + },
273 + json: {
274 + "to": `${USER_ID}`,
275 + "messages": [
276 + {
277 + "type": "text",
278 + "text": text1
279 + },
280 + {
281 + "type": "text",
282 + "text": text2
283 + }
284 + ]
285 + }
286 + }, (error, response, body) => {
287 + console.log(body)
288 + });
289 +}
290 +function PushSingleMessage(text1) {//push single message
291 + request.post(
292 + {
293 + url: PUSH_TARGET_URL,
294 + headers: {
295 + 'Authorization': `Bearer ${TOKEN}`
296 + },
297 + json: {
298 + "to": `${USER_ID}`,
299 + "messages": [
300 + {
301 + "type": "text",
302 + "text": text1
303 + }
304 + ]
305 + }
306 + }, (error, response, body) => {
307 + console.log(body)
308 + });
309 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 "cheerio": "^1.0.0-rc.11", 15 "cheerio": "^1.0.0-rc.11",
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 "puppeteer": "^14.1.1", 19 "puppeteer": "^14.1.1",
19 "selenium-webdriver": "^4.1.2" 20 "selenium-webdriver": "^4.1.2"
20 } 21 }
......