Showing
3 changed files
with
204 additions
and
30 deletions
1 | +const chatbot = require("./app.js"); | ||
2 | + | ||
1 | const request = require('request'); | 3 | const request = require('request'); |
2 | const cheerio = require('cheerio'); | 4 | const cheerio = require('cheerio'); |
3 | const puppeteer = require('puppeteer'); | 5 | const puppeteer = require('puppeteer'); |
4 | 6 | ||
7 | +require('chromedriver'); | ||
5 | const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기 | 8 | const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기 |
6 | var webdriver = require('selenium-webdriver'); | 9 | var webdriver = require('selenium-webdriver'); |
7 | var By = webdriver.By; | 10 | var By = webdriver.By; |
... | @@ -17,12 +20,14 @@ app.use(bodyParser.json()); | ... | @@ -17,12 +20,14 @@ app.use(bodyParser.json()); |
17 | 20 | ||
18 | 21 | ||
19 | const booking_url = "https://megabox.co.kr/booking"; | 22 | const booking_url = "https://megabox.co.kr/booking"; |
23 | +exports.booking_url = booking_url; | ||
20 | const rate_url = "https://www.megabox.co.kr/movie"; | 24 | const rate_url = "https://www.megabox.co.kr/movie"; |
21 | 25 | ||
22 | let r =0; | 26 | let r =0; |
23 | let movie_data = []; | 27 | let movie_data = []; |
24 | exports.movie_data = movie_data; | 28 | exports.movie_data = movie_data; |
25 | let location_data = []; | 29 | let location_data = []; |
30 | +exports.location_data = location_data; | ||
26 | let index = 0; | 31 | let index = 0; |
27 | 32 | ||
28 | 33 | ||
... | @@ -102,45 +107,91 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 | ... | @@ -102,45 +107,91 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 |
102 | ])} | 107 | ])} |
103 | 108 | ||
104 | 109 | ||
105 | -let userData = { | 110 | +const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build(); |
106 | - 'Date': '', | 111 | +let PlayingMovieList = []; |
107 | - 'location':'' | 112 | +exports.PlayingMovieList = PlayingMovieList; |
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 | 113 | ||
116 | -const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();//.setChromeOptions(new chrome.Options().headless()) | 114 | +exports.using_PlayingMovieURL = function(PlayingMovieURL){ |
115 | + async( )=>{ | ||
116 | + appdriver.get(PlayingMovieURL); | ||
117 | + appdriver.switchTo().frame(0) | ||
118 | + }//frameBokdMBooking 프레임 가져옴 | ||
119 | +} | ||
120 | +exports.geting_PlayingMovie= function(){ | ||
121 | + async( )=>{ | ||
122 | + let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); | ||
123 | + let n = 0; | ||
124 | + for (item of movie_list) { | ||
125 | + let play = 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 | + } | ||
117 | 132 | ||
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 | } | 133 | } |
134 | + console.log(PlayingMovieList); | ||
125 | } | 135 | } |
126 | 136 | ||
127 | - let PlayingMovieURL = booking_url + '?brchNo1='+userData['location']+'&playDe='+userData['Date'];//사용자 정보 바탕으로 해당 일자 영화관 영화 상영 여부 확인 | 137 | +} |
128 | 138 | ||
129 | - appdriver.get(PlayingMovieURL); | 139 | +// let userData = { |
130 | - appdriver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 | 140 | +// 'Date': '', |
131 | - res.send(movie_data); | 141 | +// 'location':'' |
142 | +// }; | ||
143 | +// // const _sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay)); | ||
144 | +// app.get('/Megabox', (req, res) => { | ||
132 | 145 | ||
133 | -}) | 146 | +// res.send(movie_data); |
147 | + | ||
148 | +// }) | ||
149 | + | ||
150 | +// app.post('/Megabox', (req, res) => {//사용자에게 Date와 location(영화관 장소) 받아옴 | ||
151 | +// let PlayingMovieURL; | ||
152 | +// userData['Date'] = req.body.Date; | ||
153 | +// for(i of location_data){ | ||
154 | +// if(i['LocationName'] == req.body.location){ | ||
155 | +// userData['location']=i['LocationNUm']; | ||
156 | +// break; | ||
157 | +// } | ||
158 | +// } | ||
159 | + | ||
160 | +// PlayingMovieURL = booking_url + '?brchNo1='+userData['location']+'&playDe='+userData['Date'];//사용자 정보 바탕으로 해당 일자 영화관 영화 상영 여부 확인 | ||
161 | + | ||
162 | +// appdriver.get(PlayingMovieURL); | ||
163 | +// appdriver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 | ||
164 | +// res.send(movie_data); | ||
165 | + | ||
166 | +// }) | ||
167 | +// app.post('/Megabox', (req, res) => {//사용자에게 Date와 location(영화관 장소) 받아옴 | ||
168 | +// userData['Date'] = req.body.Date; | ||
169 | +// for(i of location_data){ | ||
170 | +// if(i['LocationName'] == req.body.location){ | ||
171 | +// userData['location']=i['LocationNUm']; | ||
172 | +// break; | ||
173 | +// } | ||
174 | +// } | ||
175 | + | ||
176 | +// let PlayingMovieURL = booking_url + '?brchNo1='+userData['location']+'&playDe='+userData['Date'];//사용자 정보 바탕으로 해당 일자 영화관 영화 상영 여부 확인 | ||
177 | + | ||
178 | +// appdriver.get(PlayingMovieURL); | ||
179 | +// appdriver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 | ||
180 | +// res.send(movie_data); | ||
181 | + | ||
182 | +// }) | ||
134 | 183 | ||
135 | app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 여부 객체에 넣음 | 184 | app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 여부 객체에 넣음 |
136 | 185 | ||
137 | - let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); | 186 | + // let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); |
138 | - let n = 0; | 187 | + // let n = 0; |
139 | - for (item of movie_list) { | 188 | + // for (item of movie_list) { |
140 | - movie_data[n++]['running'] = await item.getAttribute('form-at') | 189 | + // movie_data[n++]['running'] = await item.getAttribute('form-at') |
141 | - } | 190 | + // } |
191 | + using_PlayingMovieURL('https://megabox.co.kr/booking?brchNo1=4451&playDe=20220606'); | ||
192 | + geting_PlayingMovie(); | ||
142 | 193 | ||
143 | - res.send(movie_data); | 194 | + res.send(PlayingMovieList); |
144 | }) | 195 | }) |
145 | 196 | ||
146 | -app.listen(23023); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
197 | +app.listen(6000); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | let megabox = require('./Megabox.js'); | 1 | let megabox = require('./Megabox.js'); |
2 | - | 2 | +const async = require('async') |
3 | megabox.init(); | 3 | megabox.init(); |
4 | + | ||
5 | +const request = require('request'); | ||
6 | +var express = require('express'); | ||
7 | +const REPLY_TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
8 | +const REPLY_TOKEN = '' | ||
9 | +const fs = require('fs'); | ||
10 | +const path = require('path'); | ||
11 | +const HTTPS = require('https'); | ||
12 | +const domain = "" | ||
13 | +const sslport = 23023; | ||
14 | +const bodyParser = require('body-parser'); | ||
15 | +var app = express(); | ||
16 | +app.use(bodyParser.json()); | ||
17 | + | ||
18 | +let MEGA_date; | ||
19 | +let MEGA_TheaterLocation; | ||
20 | +let MEGA_title; | ||
21 | +let MEGA_PlayingMovieURL; | ||
22 | +exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL; | ||
23 | + | ||
24 | +app.post('/hook', function (req, res) { | ||
25 | + | ||
26 | + var eventObj = req.body.events[0]; | ||
27 | + var source = eventObj.source; | ||
28 | + var message = eventObj.message; | ||
29 | + | ||
30 | + // request log | ||
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( | ||
38 | + { | ||
39 | + url: REPLY_TARGET_URL, | ||
40 | + headers: { | ||
41 | + 'Authorization': `Bearer ${REPLY_TOKEN}` | ||
42 | + }, | ||
43 | + json: { | ||
44 | + "replyToken":eventObj.replyToken, | ||
45 | + "messages":[ | ||
46 | + { | ||
47 | + "type":"text", | ||
48 | + "text":"영화를 보실 날짜를 입력해주세요(잘못 입력하면 당일 날짜가 들어갑니다.)" | ||
49 | + }, | ||
50 | + { | ||
51 | + "type":"text", | ||
52 | + "text":"ex)20020409" | ||
53 | + } | ||
54 | + ] | ||
55 | + } | ||
56 | + | ||
57 | + },(error, response, body) => { | ||
58 | + console.log(body) | ||
59 | + }); | ||
60 | + | ||
61 | + } | ||
62 | + if(eventObj.message.text.length===8){ | ||
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){ | ||
88 | + if(i['LocationName'] == message.text){ | ||
89 | + MEGA_TheaterLocation = i['LocationNUm']; | ||
90 | + console.log(MEGA_TheaterLocation) | ||
91 | + break; | ||
92 | + } | ||
93 | + } | ||
94 | + if(MEGA_date && MEGA_TheaterLocation){ | ||
95 | + MEGA_PlayingMovieURL = megabox.booking_url + '?brchNo1='+MEGA_TheaterLocation+'&playDe='+MEGA_date; | ||
96 | + console.log(MEGA_PlayingMovieURL) | ||
97 | + async.waterfall[ | ||
98 | + megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL), | ||
99 | + megabox.geting_PlayingMovie(), | ||
100 | + async()=>{console.log(megabox.PlayingMovieList)} | ||
101 | + ] | ||
102 | + | ||
103 | + } | ||
104 | + | ||
105 | + res.sendStatus(200); | ||
106 | + | ||
107 | +}); | ||
108 | + | ||
109 | +try { | ||
110 | + const option = { | ||
111 | + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ||
112 | + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), | ||
113 | + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | ||
114 | + }; | ||
115 | + | ||
116 | + HTTPS.createServer(option, app).listen(sslport, () => { | ||
117 | + console.log(`[HTTPS] Server is started on port ${sslport}`); | ||
118 | + }); | ||
119 | + } catch (error) { | ||
120 | + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | ||
121 | + console.log(error); | ||
122 | + } | ||
123 | + | ||
124 | + | ||
125 | + | ... | ... |
... | @@ -13,6 +13,7 @@ | ... | @@ -13,6 +13,7 @@ |
13 | "async": "^3.2.3", | 13 | "async": "^3.2.3", |
14 | "body-parser": "^1.20.0", | 14 | "body-parser": "^1.20.0", |
15 | "cheerio": "^1.0.0-rc.11", | 15 | "cheerio": "^1.0.0-rc.11", |
16 | + "chromedriver": "^101.0.0", | ||
16 | "express": "^4.18.1", | 17 | "express": "^4.18.1", |
17 | "puppeteer": "^14.1.1", | 18 | "puppeteer": "^14.1.1", |
18 | "selenium-webdriver": "^4.1.2" | 19 | "selenium-webdriver": "^4.1.2" | ... | ... |
-
Please register or login to post a comment