임승현

Merge branch 'feature/Chatbot_megabox' into 'master'

Feature/chatbot megabox



See merge request !35
const chatbot = require("./app.js");
const request = require('request');
const cheerio = require('cheerio');
const puppeteer = require('puppeteer');
require('chromedriver');
const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기
var webdriver = require('selenium-webdriver');
var By = webdriver.By;
const chrome = require('selenium-webdriver/chrome');//크롬 사용시
const async = require('async')
let express = require('express');
let app = express();
let bodyParser = require('body-parser');
const { timeout } = require('async');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const booking_url = "https://megabox.co.kr/booking?";
exports.booking_url = booking_url;
const rate_url = "https://www.megabox.co.kr/movie";
let r =0;
let movie_data = [];
exports.movie_data = movie_data;
let location_data = [];
exports.location_data = location_data;
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 프레임 가져옴
let seoul = await driver.wait(until.elementsLocated(By.css('#mCSB_4_container>ul>li>#btn')));
let Gyeonggi = await driver.wait(until.elementsLocated(By.css('#mCSB_5_container>ul>li>#btn')));
const Incheon = await driver.wait(until.elementsLocated(By.css('#mCSB_6_container>ul>li>#btn')));
const DCS = await driver.wait(until.elementsLocated(By.css('#mCSB_7_container>ul>li>#btn')));//Daejeon Chungcheong Sejong
const BDG = await driver.wait(until.elementsLocated(By.css('#mCSB_8_container>ul>li>#btn')));//Busan Daegu Gyeongsang
const GJ= await driver.wait(until.elementsLocated(By.css('#mCSB_9_container>ul>li>#btn')));//gwangju_jeonla
const Gangwon = await driver.wait(until.elementsLocated(By.css('#mCSB_10_container>ul>li>#btn')));
const location_list = [seoul, Gyeonggi, Incheon, DCS, BDG, GJ, Gangwon]//
for(let i = 0; i < location_list.length; i++){
for (item of location_list[i]) {
location_data[index++] = {
'LocationName':await item.getAttribute("brch-nm"),
'LocationNum' : await item.getAttribute("brch-no")
}
// let location_name = await item.getAttribute("brch-nm");
// let location_num = await item.getAttribute("brch-no");
// let obj = {};
// obj[location_name]= location_num
// location_data[index++] = obj;
}
}
let movie_list = await driver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
r = 0;
for (item of movie_list) {
//Using getAttribute to get the data
movie_data[r++] = {
'rank' : r,
'title' : await item.getAttribute("movie-nm"),
'movie_num':await item.getAttribute("movie-no"),
}
}
driver.close();
},
async () => {
r = 0;
const browser = await puppeteer.launch({
headless: true
});
const page = await browser.newPage();
await page.goto(rate_url);
const content = await page.content();
const $ = cheerio.load(content);
const $rate_lists = $("ol.list>li");
$rate_lists.each((index, list) => {
const name = $(list).find('div.tit-area > p.tit').attr('title');
const rate = $(list).find('div.rate-date > span.rate').text();
if(movie_data[r].title === name){
movie_data[r++]['rate'] = rate;
}
});
for(i of movie_data){
if(Object.keys(i).length==3){
movie_data[r++]['rate'] = '예매율 0%';
}
}
browser.close();
console.log("Comepleted!");
},
])}
let appdriver;
exports.using_PlayingMovieURL = async(PlayingMovieURL) => {
appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
appdriver.get(PlayingMovieURL);
//appdriver.switchTo().frame(0)
//frameBokdMBooking 프레임 가져옴
}
exports.geting_PlayingMovie= async() => {
let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
let n = 0;
console.log(movie_list);
for (item of movie_list) {
movie_data[n++]['running'] = await item.getAttribute('form-at');
}
console.log("Completed get Running");
}
app.listen(5000);
\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
{
"name": "megabox",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"async": "^3.2.3",
"body-parser": "^1.20.0",
"cheerio": "^1.0.0-rc.11",
"chromedriver": "^101.0.0",
"express": "^4.18.1",
"express-async-handler": "^1.2.0",
"moment": "^2.29.3",
"puppeteer": "^14.1.1",
"request": "^2.88.2",
"selenium-webdriver": "^4.1.2"
}
}
const chatbot = require("./app.js");
const request = require('request');
const cheerio = require('cheerio');
const puppeteer = require('puppeteer');
require('chromedriver');
const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기
var webdriver = require('selenium-webdriver');
var By = webdriver.By;
const chrome = require('selenium-webdriver/chrome');//크롬 사용시
const async = require('async')
let express = require('express');
let app = express();
let bodyParser = require('body-parser');
const { timeout } = require('async');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const booking_url = "https://megabox.co.kr/booking?";
exports.booking_url = booking_url;
const rate_url = "https://www.megabox.co.kr/movie";
let r =0;
let movie_data = [];
exports.movie_data = movie_data;
let location_data = [];
exports.location_data = location_data;
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 프레임 가져옴
let seoul = await driver.wait(until.elementsLocated(By.css('#mCSB_4_container>ul>li>#btn')));
let Gyeonggi = await driver.wait(until.elementsLocated(By.css('#mCSB_5_container>ul>li>#btn')));
const Incheon = await driver.wait(until.elementsLocated(By.css('#mCSB_6_container>ul>li>#btn')));
const DCS = await driver.wait(until.elementsLocated(By.css('#mCSB_7_container>ul>li>#btn')));//Daejeon Chungcheong Sejong
const BDG = await driver.wait(until.elementsLocated(By.css('#mCSB_8_container>ul>li>#btn')));//Busan Daegu Gyeongsang
const GJ= await driver.wait(until.elementsLocated(By.css('#mCSB_9_container>ul>li>#btn')));//gwangju_jeonla
const Gangwon = await driver.wait(until.elementsLocated(By.css('#mCSB_10_container>ul>li>#btn')));
const location_list = [seoul, Gyeonggi, Incheon, DCS, BDG, GJ, Gangwon]//
for(let i = 0; i < location_list.length; i++){
for (item of location_list[i]) {
location_data[index++] = {
'LocationName':await item.getAttribute("brch-nm"),
'LocationNum' : await item.getAttribute("brch-no")
}
// let location_name = await item.getAttribute("brch-nm");
// let location_num = await item.getAttribute("brch-no");
// let obj = {};
// obj[location_name]= location_num
// location_data[index++] = obj;
}
}
let movie_list = await driver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
r = 0;
for (item of movie_list) {
//Using getAttribute to get the data
movie_data[r++] = {
'rank' : r,
'title' : await item.getAttribute("movie-nm"),
'movie_num':await item.getAttribute("movie-no"),
}
}
driver.close();
},
async () => {
r = 0;
const browser = await puppeteer.launch({
headless: true
});
const page = await browser.newPage();
await page.goto(rate_url);
const content = await page.content();
const $ = cheerio.load(content);
const $rate_lists = $("ol.list>li");
$rate_lists.each((index, list) => {
const name = $(list).find('div.tit-area > p.tit').attr('title');
const rate = $(list).find('div.rate-date > span.rate').text();
if(movie_data[r].title === name){
movie_data[r++]['rate'] = rate;
}
});
for(i of movie_data){
if(Object.keys(i).length==3){
movie_data[r++]['rate'] = '예매율 0%';
}
}
browser.close();
console.log("Comepleted!");
},
])}
const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
exports.using_PlayingMovieURL = async(PlayingMovieURL) => {
appdriver.get(PlayingMovieURL);
//appdriver.switchTo().frame(0)
//frameBokdMBooking 프레임 가져옴
}
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) {
movie_data[n++]['running'] = await item.getAttribute('form-at');
}
console.log("Completed get Running");
}
// let userData = {
// 'Date': '',
// 'location':''
// };
// // const _sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
// app.get('/Megabox', (req, res) => {
// res.send(movie_data);
// })
// app.post('/Megabox', (req, res) => {//사용자에게 Date와 location(영화관 장소) 받아옴
// let PlayingMovieURL;
// userData['Date'] = req.body.Date;
// for(i of location_data){
// if(i['LocationName'] == req.body.location){
// userData['location']=i['LocationNum'];
// break;
// }
// }
// PlayingMovieURL = booking_url + '?brchNo1='+userData['location']+'&playDe='+userData['Date'];//사용자 정보 바탕으로 해당 일자 영화관 영화 상영 여부 확인
// appdriver.get(PlayingMovieURL);
// appdriver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴
// res.send(movie_data);
// })
// app.post('/Megabox', (req, res) => {//사용자에게 Date와 location(영화관 장소) 받아옴
// userData['Date'] = req.body.Date;
// for(i of location_data){
// if(i['LocationName'] == req.body.location){
// userData['location']=i['LocationNum'];
// break;
// }
// }
// let PlayingMovieURL = booking_url + '?brchNo1='+userData['location']+'&playDe='+userData['Date'];//사용자 정보 바탕으로 해당 일자 영화관 영화 상영 여부 확인
// appdriver.get(PlayingMovieURL);
// appdriver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴
// res.send(movie_data);
// })
app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 여부 객체에 넣음
// let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
// let n = 0;
// for (item of movie_list) {
// movie_data[n++]['running'] = await item.getAttribute('form-at')
// }
using_PlayingMovieURL('https://megabox.co.kr/booking?brchNo1=4451&playDe=20220606');
geting_PlayingMovie();
res.send(PlayingMovieList);
})
app.listen(5000);
\ No newline at end of file
This diff is collapsed. Click to expand it.
{
"name": "megabox",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"async": "^3.2.3",
"body-parser": "^1.20.0",
"cheerio": "^1.0.0-rc.11",
"chromedriver": "^101.0.0",
"express": "^4.18.1",
"puppeteer": "^14.1.1",
"express-async-handler": "^1.2.0",
"selenium-webdriver": "^4.1.2"
}
}
\ No newline at end of file
[![node](https://img.shields.io/badge/Node-v16.15.0-important?logo=nodedotjs)](https://nodejs.org/ko/) [![express](https://img.shields.io/badge/Express-4.18.1-important?logo=express)](https://expressjs.com/ko/)
[![puppeteer](https://img.shields.io/badge/puppeteer-v14.1.1-success?logo=Puppeteer)](https://github.com/puppeteer/puppeteer) [![selenium-webdriver](https://img.shields.io/badge/selenium--webdriver-v4.1.2-success?logo=Selenium)](https://www.selenium.dev/documentation/webdriver/) [![express-async-handler](https://img.shields.io/badge/express--async--handler-v1.2.0-success)](https://www.npmjs.com/package/express-async-handler) [![cheerio](https://img.shields.io/badge/cheerio-v1.0.0--rc.11-success)](https://cheerio.js.org/)
# 3대 멀티플렉스 통합 예매 챗봇
......@@ -20,40 +22,70 @@ CGV, 롯데시네마, MEGABOX 영화관의 정보를 통합 제공 및 예매를
+ Line Messaging API
+ Kakao Search-by-Keyword API
## Getting Started
### Prerequisites
## Getting Started
### Installation
1. Kakao REST API관련 KEY를 발급받습니다.
[Kakao Search API](https://developers.kakao.com/)
2. 해당 Repository를 Clone합니다.
`git clone http://khuhub.khu.ac.kr/{YourID}/Multiplex_Ticketing_Platform.git`
3. 코드를 실행하는데 필요한 npm 요소들을 Install합니다.
`npm install`
4. Line Messaging API - Webhook 설정에서 본인의 domain을 입력합니다.
![webhook](https://ifh.cc/g/gQCJw4.png)
5. 코드에 본인이 발급받은 API KEY, Domain을 입력합니다.
`const USER_ID = '{YOUR OWN LINE MESSAGING API USER_ID}';`
`const TOKEN = '{YOUR OWN LINE MESSAGING API TOKEN}';`
`const domain = '{YOUR OWN DOMAIN}';`
`const KAKAO_KEY = '{YOUR OWN KAKAO REST API KEY}';`
6. QR 코드를 휴대폰의 카메라로 스캔하거나 <__@583zdtpz__>을 친구 찾기에 입력하여 "영화관통합예매챗봇"을 추가합니다.
![](https://qr-official.line.me/sid/L/583zdtpz.png)
# Contributing
1. 해당 Repository를 Fork합니다.
`git fork http://khuhub.khu.ac.kr/2021105632/Multiplex_Ticketing_Platform.git`
2. Fork한 Repository를 Clone합니다.
`git clone http://khuhub.khu.ac.kr/{YourID}/Multiplex_Ticketing_Platform.git`
3. 당신이 개발하고자 하는 기능의 Branch를 추가합니다.
`git checkout -b feature/{YourBranchName}`
4. 기능을 구현합니다.
5. 당신이 추가한 기능 또는 수정 사항을 Commit합니다.
`git commit -m 'Add feature {FeatureName}'`
6. 당신의 Branch를 Push합니다.
`git push origin feature/{YourBranchName}`
7. Pull Request를 엽니다.
## Usage
챗봇을 추가하게 되면 자동으로 다음과 같은 메세지가 전송됩니다.
## License
![chatbot start message](https://ifh.cc/g/xfZdhM.png)
Apache License를 사용합니다. LICENSE.txt를 통해 자세한 정보를 확인해주세요.
영화 예매 링크를 받는데 까지는 총 4가지의 단계를 거치게 됩니다!
1. 브랜드 선택
2. 영화관 선택
2-1.영화관 세부 선택
3. 날짜 선택
4. 상영 중인 영화 목록에서 원하는 영화 선택
## Contact
위와 같은 단계로 입력이 모두 완료되면 선택하신 영화 예매 링크 및 영화관 위치 링크를 챗봇을 통해 바로 전달받으실 수 있습니다!!
## Contributing
> 임승현 - kevinlsh17@khu.ac.kr
1. 해당 Repository를 Fork합니다.
`git fork http://khuhub.khu.ac.kr/2021105632/Multiplex_Ticketing_Platform.git`
2. Fork한 Repository를 Clone합니다.
`git clone http://khuhub.khu.ac.kr/{YourID}/Multiplex_Ticketing_Platform.git`
3. 당신이 개발하고자 하는 기능의 Branch를 추가합니다.
`git checkout -b feature/{YourBranchName}`
4. 기능을 구현합니다.
5. 당신이 추가한 기능 또는 수정 사항을 Commit합니다.
`git commit -m 'Add feature {FeatureName}'`
6. 당신의 Branch를 Push합니다.
`git push origin feature/{YourBranchName}`
7. Pull Request를 엽니다.
> 이혜인 - hil0409@khu.ac.kr
> 신승민 - s091506@khu.ac.kr
## License
Apache License를 사용합니다. LICENSE.txt를 통해 자세한 정보를 확인해주세요.
## Contact
> 임승현 - kevinlsh17@khu.ac.kr
> 이혜인 - hil0409@khu.ac.kr
> 신승민 - s091506@khu.ac.kr
>
> Project Link: [http://khuhub.khu.ac.kr/2021105632/Multiplex_Ticketing_Platform.git](http://khuhub.khu.ac.kr/2021105632/Multiplex_Ticketing_Platform.git)
\ No newline at end of file
......