이혜인

chatbot 초기 단계

...@@ -19,7 +19,7 @@ app.use(bodyParser.urlencoded({ extended: false })); ...@@ -19,7 +19,7 @@ app.use(bodyParser.urlencoded({ extended: false }));
19 app.use(bodyParser.json()); 19 app.use(bodyParser.json());
20 20
21 21
22 -const booking_url = "https://megabox.co.kr/booking"; 22 +const booking_url = "https://megabox.co.kr/booking?";
23 exports.booking_url = booking_url; 23 exports.booking_url = booking_url;
24 const rate_url = "https://www.megabox.co.kr/movie"; 24 const rate_url = "https://www.megabox.co.kr/movie";
25 25
...@@ -33,6 +33,7 @@ let index = 0; ...@@ -33,6 +33,7 @@ let index = 0;
33 33
34 exports.init = ()=>{async.waterfall([//for 동기적 처리 34 exports.init = ()=>{async.waterfall([//for 동기적 처리
35 async () => { 35 async () => {
36 +
36 const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();// 37 const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();//
37 driver.get(booking_url); 38 driver.get(booking_url);
38 driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 39 driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴
...@@ -56,7 +57,6 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 ...@@ -56,7 +57,6 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
56 // let obj = {}; 57 // let obj = {};
57 // obj[location_name]= location_num 58 // obj[location_name]= location_num
58 // location_data[index++] = obj; 59 // location_data[index++] = obj;
59 -
60 } 60 }
61 } 61 }
62 62
...@@ -108,30 +108,17 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 ...@@ -108,30 +108,17 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
108 108
109 109
110 const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build(); 110 const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
111 -let PlayingMovieList = [];
112 -exports.PlayingMovieList = PlayingMovieList;
113 111
114 -exports.using_PlayingMovieURL = function(PlayingMovieURL){ 112 +exports.using_PlayingMovieURL = async(PlayingMovieURL) => {
115 - async( )=>{
116 appdriver.get(PlayingMovieURL); 113 appdriver.get(PlayingMovieURL);
117 - appdriver.switchTo().frame(0) 114 + //appdriver.switchTo().frame(0)
118 - }//frameBokdMBooking 프레임 가져옴 115 + //frameBokdMBooking 프레임 가져옴
119 } 116 }
120 -exports.geting_PlayingMovie= function(){ 117 +exports.geting_PlayingMovie= async() => {
121 - async( )=>{
122 let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); 118 let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
123 let n = 0; 119 let n = 0;
124 for (item of movie_list) { 120 for (item of movie_list) {
125 - let play = await item.getAttribute('form-at') 121 + movie_data[n++]['running'] = await item.getAttribute('form-at')
126 - let title = await item.getAttribute("movie-nm");
127 - if(play ==='y' ){
128 - PlayingMovieList[n++] = {
129 - title : await item.getAttribute("movie-no")
130 - }
131 - }
132 -
133 - }
134 - console.log(PlayingMovieList);
135 } 122 }
136 123
137 } 124 }
......
1 let megabox = require('./Megabox.js'); 1 let megabox = require('./Megabox.js');
2 const async = require('async') 2 const async = require('async')
3 +//let SearchingTheaterAPI = require('./SearchingTheaterAPI');
4 +
3 megabox.init(); 5 megabox.init();
4 6
5 const request = require('request'); 7 const request = require('request');
...@@ -15,25 +17,17 @@ const bodyParser = require('body-parser'); ...@@ -15,25 +17,17 @@ const bodyParser = require('body-parser');
15 var app = express(); 17 var app = express();
16 app.use(bodyParser.json()); 18 app.use(bodyParser.json());
17 19
20 +const moment = require("moment");
21 +
18 let MEGA_date; 22 let MEGA_date;
19 let MEGA_TheaterLocation; 23 let MEGA_TheaterLocation;
20 let MEGA_title; 24 let MEGA_title;
21 let MEGA_PlayingMovieURL; 25 let MEGA_PlayingMovieURL;
22 exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL; 26 exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL;
23 27
24 -app.post('/hook', function (req, res) { 28 +let MEGA_flag = 0;
25 -
26 - var eventObj = req.body.events[0];
27 - var source = eventObj.source;
28 - var message = eventObj.message;
29 29
30 - // request log 30 +function SendMessage(eventObj, text1, text2 = ""){
31 - console.log('======================', new Date() ,'======================');
32 - console.log('[request]', req.body);
33 - console.log('[request source] ', eventObj.source);
34 - console.log('[request message]', eventObj.message);
35 -
36 - if(eventObj.message.text == 3){
37 request.post( 31 request.post(
38 { 32 {
39 url: REPLY_TARGET_URL, 33 url: REPLY_TARGET_URL,
...@@ -45,63 +39,78 @@ app.post('/hook', function (req, res) { ...@@ -45,63 +39,78 @@ app.post('/hook', function (req, res) {
45 "messages":[ 39 "messages":[
46 { 40 {
47 "type":"text", 41 "type":"text",
48 - "text":"영화를 보실 날짜를 입력해주세요(잘못 입력하면 당일 날짜가 들어갑니다.)" 42 + "text":text1
49 }, 43 },
50 { 44 {
51 "type":"text", 45 "type":"text",
52 - "text":"ex)20020409" 46 + "text":text2
53 } 47 }
54 ] 48 ]
55 } 49 }
56 50
57 },(error, response, body) => { 51 },(error, response, body) => {
58 - console.log(body) 52 + //console.log(body)
59 }); 53 });
54 +}
60 55
56 +app.post('/hook', function (req, res) {
57 +
58 + var eventObj = req.body.events[0];
59 + var source = eventObj.source;
60 + var message = eventObj.message;
61 +
62 + // request log
63 + console.log('======================', new Date() ,'======================');
64 + console.log('[request]', req.body);
65 + console.log('[request source] ', eventObj.source);
66 + console.log('[request message]', eventObj.message);
67 +
68 + if(eventObj.message.text == 3 && MEGA_flag === 0){
69 + const text1 = "영화관 위치를 입력해주세요";
70 + const text2 = "ex1)강남, ex2)강남시티";
71 +
72 + SendMessage(eventObj, text1, text2);
73 + MEGA_flag++;
61 } 74 }
62 - if(eventObj.message.text.length===8){ 75 + if(MEGA_flag===1){
63 - MEGA_date = parseInt(message.text);
64 - request.post(
65 - {
66 - url: REPLY_TARGET_URL,
67 - headers: {
68 - 'Authorization': `Bearer ${REPLY_TOKEN}`
69 - },
70 - json: {
71 - "replyToken":eventObj.replyToken,
72 - "messages":[
73 - {
74 - "type":"text",
75 - "text":"영화관 위치를 입력해주세요"
76 - },
77 - {
78 - "type":"text",
79 - "text":"ex1)강남, ex2)강남시티"
80 - }
81 - ]
82 - }
83 - },(error, response, body) => {
84 - console.log(body)
85 - });
86 - }
87 for(i of megabox.location_data){ 76 for(i of megabox.location_data){
88 - if(i['LocationName'] == message.text){ 77 +
78 + if(i['LocationName'] === message.text){
89 MEGA_TheaterLocation = i['LocationNUm']; 79 MEGA_TheaterLocation = i['LocationNUm'];
90 - console.log(MEGA_TheaterLocation) 80 + console.log(MEGA_TheaterLocation);
81 + MEGA_flag++;
91 break; 82 break;
92 } 83 }
93 } 84 }
85 +
86 + }else{
87 + SendMessage(eventObj, "다시입력해주세요");
88 + }
89 +
90 + if(MEGA_flag === 2){
91 + MEGA_date = parseInt(message.text);
92 + const text1 = "영화를 보실 날짜를 입력해주세요.";
93 + const text2 = "ex)20020409";
94 +
95 + SendMessage(eventObj, text1, text2);
96 + ++MEGA_flag;
97 + }
98 +
99 + if(moment(eventObj.message.text, "YYYYMMDD", true).isValid() && MEGA_flag===3){
100 + console.log(3);
94 if(MEGA_date && MEGA_TheaterLocation){ 101 if(MEGA_date && MEGA_TheaterLocation){
95 - MEGA_PlayingMovieURL = megabox.booking_url + '?brchNo1='+MEGA_TheaterLocation+'&playDe='+MEGA_date; 102 + MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1='+MEGA_TheaterLocation+'&playDe='+MEGA_date;
96 console.log(MEGA_PlayingMovieURL) 103 console.log(MEGA_PlayingMovieURL)
97 async.waterfall[ 104 async.waterfall[
98 megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL), 105 megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL),
99 - megabox.geting_PlayingMovie(), 106 + megabox.geting_PlayingMovie()
100 - async()=>{console.log(megabox.PlayingMovieList)}
101 ] 107 ]
102 - 108 + MEGA_flag++
109 + }
110 + }
111 + if(MEGA_flag===4){
112 + console.log(megabox.movie_data);
103 } 113 }
104 -
105 res.sendStatus(200); 114 res.sendStatus(200);
106 115
107 }); 116 });
......