Showing
3 changed files
with
169 additions
and
0 deletions
Chatbot/Megabox.js
0 → 100644
1 | +const request = require('request'); | ||
2 | +const cheerio = require('cheerio'); | ||
3 | +const puppeteer = require('puppeteer'); | ||
4 | + | ||
5 | +const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기 | ||
6 | +var webdriver = require('selenium-webdriver'); | ||
7 | +var By = webdriver.By; | ||
8 | +const chrome = require('selenium-webdriver/chrome');//크롬 사용시 | ||
9 | + | ||
10 | +const async = require('async') | ||
11 | +let express = require('express'); | ||
12 | +let app = express(); | ||
13 | +let bodyParser = require('body-parser'); | ||
14 | +const { timeout } = require('async'); | ||
15 | +app.use(bodyParser.urlencoded({ extended: false })); | ||
16 | +app.use(bodyParser.json()); | ||
17 | + | ||
18 | + | ||
19 | +const booking_url = "https://megabox.co.kr/booking"; | ||
20 | +const rate_url = "https://www.megabox.co.kr/movie"; | ||
21 | + | ||
22 | +let r =0; | ||
23 | +let movie_data = []; | ||
24 | +exports.movie_data = movie_data; | ||
25 | +let location_data = []; | ||
26 | +let index = 0; | ||
27 | + | ||
28 | + | ||
29 | +exports.init = ()=>{async.waterfall([//for 동기적 처리 | ||
30 | + async () => { | ||
31 | + const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();// | ||
32 | + driver.get(booking_url); | ||
33 | + driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 | ||
34 | + | ||
35 | + let seoul = await driver.wait(until.elementsLocated(By.css('#mCSB_4_container>ul>li>#btn'))); | ||
36 | + let Gyeonggi = await driver.wait(until.elementsLocated(By.css('#mCSB_5_container>ul>li>#btn'))); | ||
37 | + const Incheon = await driver.wait(until.elementsLocated(By.css('#mCSB_6_container>ul>li>#btn'))); | ||
38 | + const DCS = await driver.wait(until.elementsLocated(By.css('#mCSB_7_container>ul>li>#btn')));//Daejeon Chungcheong Sejong | ||
39 | + const BDG = await driver.wait(until.elementsLocated(By.css('#mCSB_8_container>ul>li>#btn')));//Busan Daegu Gyeongsang | ||
40 | + const GJ= await driver.wait(until.elementsLocated(By.css('#mCSB_9_container>ul>li>#btn')));//gwangju_jeonla | ||
41 | + const Gangwon = await driver.wait(until.elementsLocated(By.css('#mCSB_10_container>ul>li>#btn'))); | ||
42 | + const location_list = [seoul, Gyeonggi, Incheon, DCS, BDG, GJ, Gangwon]// | ||
43 | + for(let i = 0; i < location_list.length; i++){ | ||
44 | + for (item of location_list[i]) { | ||
45 | + location_data[index++] = { | ||
46 | + 'LocationName':await item.getAttribute("brch-nm"), | ||
47 | + 'LocationNUm' : await item.getAttribute("brch-no") | ||
48 | + } | ||
49 | + // let location_name = await item.getAttribute("brch-nm"); | ||
50 | + // let location_num = await item.getAttribute("brch-no"); | ||
51 | + // let obj = {}; | ||
52 | + // obj[location_name]= location_num | ||
53 | + // location_data[index++] = obj; | ||
54 | + | ||
55 | + } | ||
56 | + } | ||
57 | + | ||
58 | + let movie_list = await driver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); | ||
59 | + r = 0; | ||
60 | + for (item of movie_list) { | ||
61 | + //Using getAttribute to get the data | ||
62 | + movie_data[r++] = { | ||
63 | + 'rank' : r, | ||
64 | + 'title' : await item.getAttribute("movie-nm"), | ||
65 | + 'movie_num':await item.getAttribute("movie-no"), | ||
66 | + } | ||
67 | + } | ||
68 | + | ||
69 | + driver.close(); | ||
70 | + | ||
71 | + }, | ||
72 | + | ||
73 | + async () => { | ||
74 | + | ||
75 | + r = 0; | ||
76 | + const browser = await puppeteer.launch({ | ||
77 | + headless: true | ||
78 | + }); | ||
79 | + const page = await browser.newPage(); | ||
80 | + await page.goto(rate_url); | ||
81 | + const content = await page.content(); | ||
82 | + | ||
83 | + const $ = cheerio.load(content); | ||
84 | + const $rate_lists = $("ol.list>li"); | ||
85 | + $rate_lists.each((index, list) => { | ||
86 | + const name = $(list).find('div.tit-area > p.tit').attr('title'); | ||
87 | + const rate = $(list).find('div.rate-date > span.rate').text(); | ||
88 | + | ||
89 | + if(movie_data[r].title === name){ | ||
90 | + movie_data[r++]['rate'] = rate; | ||
91 | + } | ||
92 | + }); | ||
93 | + for(i of movie_data){ | ||
94 | + if(Object.keys(i).length==3){ | ||
95 | + movie_data[r++]['rate'] = '예매율 0%'; | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + browser.close(); | ||
100 | + }, | ||
101 | + | ||
102 | +])} | ||
103 | + | ||
104 | + | ||
105 | +let userData = { | ||
106 | + 'Date': '', | ||
107 | + 'location':'' | ||
108 | +}; | ||
109 | +// const _sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay)); | ||
110 | +app.get('/Megabox', (req, res) => { | ||
111 | + | ||
112 | + res.send(movie_data); | ||
113 | + | ||
114 | +}) | ||
115 | + | ||
116 | +const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();//.setChromeOptions(new chrome.Options().headless()) | ||
117 | + | ||
118 | +app.post('/Megabox', (req, res) => {//사용자에게 Date와 location(영화관 장소) 받아옴 | ||
119 | + userData['Date'] = req.body.Date; | ||
120 | + for(i of location_data){ | ||
121 | + if(i['LocationName'] == req.body.location){ | ||
122 | + userData['location']=i['LocationNUm']; | ||
123 | + break; | ||
124 | + } | ||
125 | + } | ||
126 | + | ||
127 | + let PlayingMovieURL = booking_url + '?brchNo1='+userData['location']+'&playDe='+userData['Date'];//사용자 정보 바탕으로 해당 일자 영화관 영화 상영 여부 확인 | ||
128 | + | ||
129 | + appdriver.get(PlayingMovieURL); | ||
130 | + appdriver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 | ||
131 | + res.send(movie_data); | ||
132 | + | ||
133 | +}) | ||
134 | + | ||
135 | +app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 여부 객체에 넣음 | ||
136 | + | ||
137 | + let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); | ||
138 | + let n = 0; | ||
139 | + for (item of movie_list) { | ||
140 | + movie_data[n++]['running'] = await item.getAttribute('form-at') | ||
141 | + } | ||
142 | + | ||
143 | + res.send(movie_data); | ||
144 | +}) | ||
145 | + | ||
146 | +app.listen(23023); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
Chatbot/app.js
0 → 100644
Chatbot/package.json
0 → 100644
1 | +{ | ||
2 | + "name": "megabox", | ||
3 | + "version": "1.0.0", | ||
4 | + "description": "", | ||
5 | + "main": "app.js", | ||
6 | + "scripts": { | ||
7 | + "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | + }, | ||
9 | + "keywords": [], | ||
10 | + "author": "", | ||
11 | + "license": "ISC", | ||
12 | + "dependencies": { | ||
13 | + "async": "^3.2.3", | ||
14 | + "body-parser": "^1.20.0", | ||
15 | + "cheerio": "^1.0.0-rc.11", | ||
16 | + "express": "^4.18.1", | ||
17 | + "puppeteer": "^14.1.1", | ||
18 | + "selenium-webdriver": "^4.1.2" | ||
19 | + } | ||
20 | +} |
-
Please register or login to post a comment