이혜인

chatbot 초기 단계

......@@ -19,7 +19,7 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const booking_url = "https://megabox.co.kr/booking";
const booking_url = "https://megabox.co.kr/booking?";
exports.booking_url = booking_url;
const rate_url = "https://www.megabox.co.kr/movie";
......@@ -33,6 +33,7 @@ let index = 0;
exports.init = ()=>{async.waterfall([//for 동기적 처리
async () => {
const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();//
driver.get(booking_url);
driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴
......@@ -56,7 +57,6 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
// let obj = {};
// obj[location_name]= location_num
// location_data[index++] = obj;
}
}
......@@ -108,30 +108,17 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
let PlayingMovieList = [];
exports.PlayingMovieList = PlayingMovieList;
exports.using_PlayingMovieURL = function(PlayingMovieURL){
async( )=>{
exports.using_PlayingMovieURL = async(PlayingMovieURL) => {
appdriver.get(PlayingMovieURL);
appdriver.switchTo().frame(0)
}//frameBokdMBooking 프레임 가져옴
//appdriver.switchTo().frame(0)
//frameBokdMBooking 프레임 가져옴
}
exports.geting_PlayingMovie= function(){
async( )=>{
exports.geting_PlayingMovie= async() => {
let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
let n = 0;
for (item of movie_list) {
let play = await item.getAttribute('form-at')
let title = await item.getAttribute("movie-nm");
if(play ==='y' ){
PlayingMovieList[n++] = {
title : await item.getAttribute("movie-no")
}
}
}
console.log(PlayingMovieList);
movie_data[n++]['running'] = await item.getAttribute('form-at')
}
}
......
let megabox = require('./Megabox.js');
const async = require('async')
//let SearchingTheaterAPI = require('./SearchingTheaterAPI');
megabox.init();
const request = require('request');
......@@ -15,25 +17,17 @@ const bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
const moment = require("moment");
let MEGA_date;
let MEGA_TheaterLocation;
let MEGA_title;
let MEGA_PlayingMovieURL;
exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL;
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
let MEGA_flag = 0;
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
if(eventObj.message.text == 3){
function SendMessage(eventObj, text1, text2 = ""){
request.post(
{
url: REPLY_TARGET_URL,
......@@ -45,63 +39,78 @@ app.post('/hook', function (req, res) {
"messages":[
{
"type":"text",
"text":"영화를 보실 날짜를 입력해주세요(잘못 입력하면 당일 날짜가 들어갑니다.)"
"text":text1
},
{
"type":"text",
"text":"ex)20020409"
"text":text2
}
]
}
},(error, response, body) => {
console.log(body)
//console.log(body)
});
}
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
if(eventObj.message.text == 3 && MEGA_flag === 0){
const text1 = "영화관 위치를 입력해주세요";
const text2 = "ex1)강남, ex2)강남시티";
SendMessage(eventObj, text1, text2);
MEGA_flag++;
}
if(eventObj.message.text.length===8){
MEGA_date = parseInt(message.text);
request.post(
{
url: REPLY_TARGET_URL,
headers: {
'Authorization': `Bearer ${REPLY_TOKEN}`
},
json: {
"replyToken":eventObj.replyToken,
"messages":[
{
"type":"text",
"text":"영화관 위치를 입력해주세요"
},
{
"type":"text",
"text":"ex1)강남, ex2)강남시티"
}
]
}
},(error, response, body) => {
console.log(body)
});
}
if(MEGA_flag===1){
for(i of megabox.location_data){
if(i['LocationName'] == message.text){
if(i['LocationName'] === message.text){
MEGA_TheaterLocation = i['LocationNUm'];
console.log(MEGA_TheaterLocation)
console.log(MEGA_TheaterLocation);
MEGA_flag++;
break;
}
}
}else{
SendMessage(eventObj, "다시입력해주세요");
}
if(MEGA_flag === 2){
MEGA_date = parseInt(message.text);
const text1 = "영화를 보실 날짜를 입력해주세요.";
const text2 = "ex)20020409";
SendMessage(eventObj, text1, text2);
++MEGA_flag;
}
if(moment(eventObj.message.text, "YYYYMMDD", true).isValid() && MEGA_flag===3){
console.log(3);
if(MEGA_date && MEGA_TheaterLocation){
MEGA_PlayingMovieURL = megabox.booking_url + '?brchNo1='+MEGA_TheaterLocation+'&playDe='+MEGA_date;
MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1='+MEGA_TheaterLocation+'&playDe='+MEGA_date;
console.log(MEGA_PlayingMovieURL)
async.waterfall[
megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL),
megabox.geting_PlayingMovie(),
async()=>{console.log(megabox.PlayingMovieList)}
megabox.geting_PlayingMovie()
]
MEGA_flag++
}
}
if(MEGA_flag===4){
console.log(megabox.movie_data);
}
res.sendStatus(200);
});
......