Toggle navigation
Toggle navigation
This project
Loading...
Sign in
임승현
/
Multiplex_Ticketing_Platform
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이혜인
2022-06-04 20:56:01 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cd9d16e4685d6d8a3b16fa5609ee2ac506ba01b4
cd9d16e4
1 parent
60497e00
adding reply test
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
204 additions
and
30 deletions
Chatbot/Megabox.js
Chatbot/app.js
Chatbot/package.json
Chatbot/Megabox.js
View file @
cd9d16e
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
;
...
...
@@ -17,12 +20,14 @@ 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
;
...
...
@@ -102,45 +107,91 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
])}
let
userData
=
{
'Date'
:
''
,
'location'
:
''
};
// const _sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
app
.
get
(
'/Megabox'
,
(
req
,
res
)
=>
{
res
.
send
(
movie_data
);
})
const
appdriver
=
new
webdriver
.
Builder
().
forBrowser
(
'chrome'
).
setChromeOptions
(
new
chrome
.
Options
().
headless
()).
build
();
let
PlayingMovieList
=
[];
exports
.
PlayingMovieList
=
PlayingMovieList
;
const
appdriver
=
new
webdriver
.
Builder
().
forBrowser
(
'chrome'
).
setChromeOptions
(
new
chrome
.
Options
().
headless
()).
build
();
//.setChromeOptions(new chrome.Options().headless())
exports
.
using_PlayingMovieURL
=
function
(
PlayingMovieURL
){
async
(
)
=>
{
appdriver
.
get
(
PlayingMovieURL
);
appdriver
.
switchTo
().
frame
(
0
)
}
//frameBokdMBooking 프레임 가져옴
}
exports
.
geting_PlayingMovie
=
function
(){
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"
)
}
}
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
;
}
console
.
log
(
PlayingMovieList
);
}
let
PlayingMovieURL
=
booking_url
+
'?brchNo1='
+
userData
[
'location'
]
+
'&playDe='
+
userData
[
'Date'
];
//사용자 정보 바탕으로 해당 일자 영화관 영화 상영 여부 확인
}
appdriver
.
get
(
PlayingMovieURL
);
appdriver
.
switchTo
().
frame
(
0
)
//frameBokdMBooking 프레임 가져옴
res
.
send
(
movie_data
);
// 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'
)
}
// 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
(
movie_data
);
res
.
send
(
PlayingMovieList
);
})
app
.
listen
(
23023
);
\ No newline at end of file
app
.
listen
(
6000
);
\ No newline at end of file
...
...
Chatbot/app.js
View file @
cd9d16e
let
megabox
=
require
(
'./Megabox.js'
);
const
async
=
require
(
'async'
)
megabox
.
init
();
const
request
=
require
(
'request'
);
var
express
=
require
(
'express'
);
const
REPLY_TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
REPLY_TOKEN
=
''
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
""
const
sslport
=
23023
;
const
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
app
.
use
(
bodyParser
.
json
());
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
;
// 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
){
request
.
post
(
{
url
:
REPLY_TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
REPLY_TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"영화를 보실 날짜를 입력해주세요(잘못 입력하면 당일 날짜가 들어갑니다.)"
},
{
"type"
:
"text"
,
"text"
:
"ex)20020409"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
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
)
});
}
for
(
i
of
megabox
.
location_data
){
if
(
i
[
'LocationName'
]
==
message
.
text
){
MEGA_TheaterLocation
=
i
[
'LocationNUm'
];
console
.
log
(
MEGA_TheaterLocation
)
break
;
}
}
if
(
MEGA_date
&&
MEGA_TheaterLocation
){
MEGA_PlayingMovieURL
=
megabox
.
booking_url
+
'?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
)}
]
}
res
.
sendStatus
(
200
);
});
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
key
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/privkey.pem'
),
'utf8'
).
toString
(),
cert
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/cert.pem'
),
'utf8'
).
toString
(),
};
HTTPS
.
createServer
(
option
,
app
).
listen
(
sslport
,
()
=>
{
console
.
log
(
`[HTTPS] Server is started on port
${
sslport
}
`
);
});
}
catch
(
error
)
{
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
...
...
Chatbot/package.json
View file @
cd9d16e
...
...
@@ -13,6 +13,7 @@
"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"
,
"selenium-webdriver"
:
"^4.1.2"
...
...
Please
register
or
login
to post a comment