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-07 02:31:09 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b8a28b47fe0f9dbb3b66fecba50c4f210f598670
b8a28b47
1 parent
a104d8b8
modify getting playingmovielist
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
272 additions
and
312 deletions
Chatbot/Megabox.js
Chatbot/app.js
Chatbot/package.json
Chatbot/Megabox.js
View file @
b8a28b4
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
();
...
...
@@ -17,27 +14,20 @@ 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'
)));
...
...
@@ -50,7 +40,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
for
(
item
of
location_list
[
i
])
{
location_data
[
index
++
]
=
{
'LocationName'
:
await
item
.
getAttribute
(
"brch-nm"
),
'LocationN
U
m'
:
await
item
.
getAttribute
(
"brch-no"
)
'LocationN
u
m'
:
await
item
.
getAttribute
(
"brch-no"
)
}
// let location_name = await item.getAttribute("brch-nm");
// let location_num = await item.getAttribute("brch-no");
...
...
@@ -59,14 +49,12 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
// 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"
),
}
...
...
@@ -75,9 +63,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
driver
.
close
();
},
async
()
=>
{
r
=
0
;
const
browser
=
await
puppeteer
.
launch
({
headless
:
true
...
...
@@ -101,16 +87,16 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
movie_data
[
r
++
][
'rate'
]
=
'예매율 0%'
;
}
}
console
.
log
(
"completed"
)
browser
.
close
();
console
.
log
(
"Comepleted!"
);
},
])}
const
appdriver
=
new
webdriver
.
Builder
().
forBrowser
(
'chrome'
).
setChromeOptions
(
new
chrome
.
Options
().
headless
()).
build
();
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 프레임 가져옴
...
...
@@ -118,24 +104,12 @@ exports.using_PlayingMovieURL = async(PlayingMovieURL) => {
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
(
item
.
getAttribute
(
'form-at'
))
movie_data
[
n
++
][
'running'
]
=
await
item
.
getAttribute
(
'form-at'
);
}
console
.
log
(
"completed"
)
console
.
log
(
"Completed get Running"
);
}
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
(
8000
);
\ No newline at end of file
app
.
listen
(
5000
);
\ No newline at end of file
...
...
Chatbot/app.js
View file @
b8a28b4
let
megabox
=
require
(
'./Megabox.js'
);
const
async
=
require
(
'async'
)
//let SearchingTheaterAPI = require('./SearchingTheaterAPI');
megabox
.
init
();
const
request
=
require
(
'request'
);
var
express
=
require
(
'express'
);
const
megabox
=
require
(
'./Megabox.js'
);
//const SearchingTheaterAPI = require('./SearchingTheaterAPI');
const
async
=
require
(
'async'
);
megabox
.
init
();
//메가박스 코드 시작(영화관 리스트 가져오기)
const
PUSH_TARGET_URL
=
'https://api.line.me/v2/bot/message/push'
const
USER_ID
=
''
const
REPLY_TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
''
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
asyncHandler
=
require
(
'express-async-handler'
)
const
bodyParser
=
require
(
'body-parser'
);
const
request
=
require
(
'request'
);
const
moment
=
require
(
"moment"
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
""
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
const
sslport
=
23023
;
const
bodyParser
=
require
(
'body-parser
'
);
var
express
=
require
(
'express
'
);
var
app
=
express
();
app
.
use
(
bodyParser
.
json
());
const
moment
=
require
(
"moment"
);
/////////////////////////////////////////////////
// commit 할때 지워야 할것들
const
USER_ID
=
''
const
TOKEN
=
''
const
domain
=
""
let
MEGA_date
;
let
MEGA_TheaterLocation
;
let
MEGA_TheaterLocationCode
;
let
MEGA_PlayingMovieList
=
[];
let
MEGA_title
;
let
MEGA_PlayingMovieURL
;
let
initFlag
=
false
;
//브랜드 선택 flag
let
MEGA_flag
=
-
1
;
//메가박스 인지 확인하는 flag
let
MEGA_count
;
//메가박스에서 영화관 판단하는 count
let
MEGA_AbleLocationList
=
[];
//메가박스에서 영화관 이름 매치하는 것 저장하는 list
exports
.
MEGA_PlayingMovieURL
=
MEGA_PlayingMovieURL
;
////////////////////////////////////////////////
//처음 영화관을 가져오는 것까지 대략 30초가 걸림 => 30초 기다리고 메세지 전송
let
MEGA_flag
=
0
;
function
SendMessage
(
eventObj
,
text1
,
text2
=
""
){
request
.
post
(
{
url
:
REPLY_TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
text1
},
{
"type"
:
"text"
,
"text"
:
text2
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
);
});
}
function
PushMessage
(
eventObj
,
text1
,
text2
=
""
){
request
.
post
(
{
url
:
PUSH_TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"to"
:
`
${
USER_ID
}
`
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
text1
},
{
"type"
:
"text"
,
"text"
:
text2
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
function
PusbuttonhMessage
(
final_URL
){
request
.
post
(
{
url
:
PUSH_TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"to"
:
`
${
USER_ID
}
`
,
"type"
:
"template"
,
"altText"
:
"this is a carousel template"
,
"template"
:
{
"type"
:
"carousel"
,
"columns"
:
[
{
"thumbnailImageUrl"
:
"https://megabox.co.kr/SharedImg/2022/05/16/WApIttC9CrStYU7j7jzFRlc2HsIXBQtY_150.jpg"
,
"imageBackgroundColor"
:
"#FFFFFF"
,
"title"
:
"this is menu"
,
"text"
:
"description"
,
"defaultAction"
:
{
"type"
:
"uri"
,
"label"
:
"View detail"
,
"uri"
:
"https://megabox.co.kr/"
},
"actions"
:
[
{
"type"
:
"message"
,
"label"
:
"Yes"
,
"text"
:
"Yes"
},
{
"type"
:
"message"
,
"label"
:
"Yes"
,
"text"
:
"Yes"
},
{
"type"
:
"uri"
,
"label"
:
"View detail"
,
"uri"
:
"https://megabox.co.kr/"
}
]
},
{
"thumbnailImageUrl"
:
"https://example.com/bot/images/item2.jpg"
,
"imageBackgroundColor"
:
"#000000"
,
"title"
:
"this is menu"
,
"text"
:
"description"
,
"defaultAction"
:
{
"type"
:
"uri"
,
"label"
:
"View detail"
,
"uri"
:
"http://example.com/page/222"
},
"actions"
:
[
{
"type"
:
"message"
,
"label"
:
"Yes"
,
"text"
:
"Yes"
},
{
"type"
:
"message"
,
"label"
:
"Yes"
,
"text"
:
"Yes"
},
{
"type"
:
"uri"
,
"label"
:
"View detail"
,
"uri"
:
"https://megabox.co.kr/"
}
]
}
],
"imageAspectRatio"
:
"rectangle"
,
"imageSize"
:
"cover"
}
}
// {
// "type": "template",
// //"altText": "This is a buttons template",
// "template": {
// "type": "buttons",
// "thumbnailImageUrl": "https://megabox.co.kr/SharedImg/2022/05/16/WApIttC9CrStYU7j7jzFRlc2HsIXBQtY_150.jpg",
// "imageAspectRatio": "rectangle",
// "imageSize": "cover",
// "imageBackgroundColor": "#FFFFFF",
// "title": "Menu",
// "text": "Please select",
// "actions": [
// {
// "type": "message",
// "label": "Yes",
// "text": "yes"
// },
// {
// "type": "uri",
// "label": "View detail",
// "uri": final_URL
// }
// ]
// }
//}
}
)}
app
.
post
(
'/hook'
,
(
req
,
res
)
=>
{
setTimeout
(
function
()
{
PushSingleMessage
(
"원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요."
);
},
30000
);
//app.post('/hook', function (req, res) {
app
.
post
(
'/hook'
,
asyncHandler
(
async
(
req
,
res
,
next
)
=>
{
var
eventObj
=
req
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
// request log
console
.
log
(
'======================'
,
new
Date
()
,
'======================'
);
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)강남"
;
SendMessage
(
eventObj
,
text1
,
text2
);
MEGA_flag
++
;
PusbuttonhMessage
(
"https://developers.line.biz/en/reference/messaging-api/#message-common-properties"
);
console
.
log
(
MEGA_flag
)
//어느 순간에서든 "브랜드"를 입력해 원하는 브랜드 선택
//initFlag : false ==> 브랜드 선택 전
//initFlag : true ==> 브랜드 선택 됨
if
(
eventObj
.
message
.
text
==
"브랜드"
)
{
initFlag
=
false
;
MEGA_flag
=
-
1
;
PushSingleMessage
(
"원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요."
);
}
if
(
MEGA_flag
===
1
){
console
.
log
(
MEGA_flag
);
for
(
i
of
megabox
.
location_data
){
if
(
i
[
'LocationName'
]
===
message
.
text
){
MEGA_TheaterLocation
=
i
[
'LocationNUm'
];
console
.
log
(
MEGA_TheaterLocation
);
//브랜드 선택- 메가박스 인 경우 MEGA_flag를 0으로 두어 메가박스 임을 확인
if
(
initFlag
==
false
&&
eventObj
.
message
.
text
==
3
)
{
initFlag
=
true
;
MEGA_flag
=
0
;
}
//메가박스로 브랜드 선택된 경우
if
(
initFlag
==
true
&&
MEGA_flag
!=
-
1
)
{
if
(
MEGA_flag
==
0
)
{
const
text1
=
"영화관 위치를 입력해주세요"
;
const
text2
=
"ex1)강남"
;
SendMessage
(
eventObj
,
text1
,
text2
);
MEGA_flag
++
;
//PusbuttonhMessage("https://developers.line.biz/en/reference/messaging-api/#message-common-properties");
//console.log(MEGA_flag)
}
else
if
(
MEGA_flag
===
1
)
{
MEGA_count
=
0
;
//MEGA_count 초기화
MEGA_AbleLocationList
.
length
=
0
;
//MEGA_AbleLocationList 초기화
for
(
i
of
megabox
.
location_data
)
{
if
(
i
[
'LocationName'
].
includes
(
message
.
text
))
{
MEGA_AbleLocationList
[
MEGA_count
++
]
=
i
;
}
}
if
(
MEGA_count
==
1
)
{
//결과 1개 => 바로 다음 단계 넘어가기
MEGA_TheaterLocation
=
MEGA_AbleLocationList
[
0
].
LocationName
;
MEGA_TheaterLocationCode
=
MEGA_AbleLocationList
[
0
].
LocationNum
;
console
.
log
(
MEGA_TheaterLocation
,
MEGA_TheaterLocationCode
);
MEGA_flag
++
;
console
.
log
(
MEGA_flag
)
break
;
}
else
if
(
MEGA_count
>
1
)
{
//결과 2개 이상 => 리스트 출력해주고 번호로 입력받아 넘어가기
console
.
log
(
MEGA_AbleLocationList
[
0
],
MEGA_AbleLocationList
[
1
]);
let
MEGA_OutputString
=
"원하시는 상영관의 번호를 정확히 입력해주세요\n"
;
//메가박스 영화관 가능 정보 string
//PushSingleMessage("원하시는 상영관의 번호를 정확히 입력해주세요");
for
(
let
x
=
0
;
x
<
MEGA_count
;
x
++
)
{
//PushSingleMessage(String(x + 1) + ": " + MEGA_AbleLocationList[x].LocationName);
MEGA_OutputString
+=
String
(
x
+
1
)
+
": "
+
MEGA_AbleLocationList
[
x
].
LocationName
+
"\n"
;
console
.
log
(
String
(
x
+
1
),
MEGA_AbleLocationList
[
x
].
LocationName
);
}
MEGA_OutputString
+=
String
(
MEGA_count
+
1
)
+
": 다시 검색하기"
;
PushSingleMessage
(
MEGA_OutputString
);
MEGA_flag
=
101
;
}
else
{
PushSingleMessage
(
"다시 입력해주세요."
);
}
//원본 코드
//console.log(MEGA_flag);
// for (i of megabox.location_data) {
// if (i['LocationName'] === message.text) {
// MEGA_TheaterLocationCode = i['LocationNUm'];
// console.log(MEGA_TheaterLocationCode);
// MEGA_flag++;
// console.log(MEGA_flag)
// break;
// }
// }
}
else
if
(
MEGA_flag
==
101
)
{
// 0< input || input > MEGA_count+1 : 다시 검색
let
tempNum
=
parseInt
(
message
.
text
);
if
(
tempNum
>
0
&&
tempNum
<
MEGA_count
+
1
)
{
//번호에 맞는 LocationCode 전달
MEGA_TheaterLocation
=
MEGA_AbleLocationList
[
tempNum
-
1
].
LocationName
;
MEGA_TheaterLocationCode
=
MEGA_AbleLocationList
[
tempNum
-
1
].
LocationNum
;
console
.
log
(
MEGA_TheaterLocation
,
MEGA_TheaterLocationCode
);
MEGA_flag
=
2
;
}
else
{
//다시 장소 입력받기
const
text1
=
"영화관 위치를 입력해주세요"
;
const
text2
=
"ex1)강남"
;
SendMessage
(
eventObj
,
text1
,
text2
);
MEGA_flag
=
1
;
}
}
}
if
(
MEGA_flag
===
2
){
const
text1
=
"영화를 보실 날짜를 입력해주세요."
;
const
text2
=
"ex)20020409"
;
SendMessage
(
eventObj
,
text1
,
text2
);
++
MEGA_flag
;
}
if
(
moment
(
eventObj
.
message
.
text
,
"YYYYMMDD"
,
true
).
isValid
()
&&
MEGA_flag
===
3
){
MEGA_date
=
parseInt
(
eventObj
.
message
.
text
);
if
(
MEGA_date
&&
MEGA_TheaterLocation
){
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
()
]
MEGA_flag
++
console
.
log
(
MEGA_flag
);
//날짜 입력 받기
if
(
MEGA_flag
==
2
)
{
const
text1
=
"현재 영화관은 "
+
MEGA_TheaterLocation
+
" 입니다.\n영화를 보실 날짜를 입력해주세요."
;
const
text2
=
"ex)20020409"
;
SendMessage
(
eventObj
,
text1
,
text2
);
MEGA_flag
=
3
;
}
}
if
(
MEGA_flag
===
4
){
let
obj
=
{};
let
n
;
let
PlayingMovie
=
"-현재 상영작-\n\n"
;
const
text1
=
"현재상영작을 가져오는 중입니다."
;
const
text2
=
"잠시만 기다려주세요."
;
PushMessage
(
eventObj
,
text1
,
text2
);
setTimeout
(
function
()
{
//날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기
if
(
moment
(
message
.
text
,
"YYYYMMDD"
,
true
).
isValid
()
&&
MEGA_flag
==
3
)
{
MEGA_date
=
parseInt
(
message
.
text
);
//console.log(MEGA_date, MEGA_TheaterLocation);
if
(
MEGA_date
&&
MEGA_TheaterLocationCode
)
{
const
text1
=
"현재상영작을 가져오는 중입니다."
;
const
text2
=
"잠시만 기다려주세요."
;
PushMessage
(
text1
,
text2
);
MEGA_PlayingMovieURL
=
"https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do"
+
'?brchNo1='
+
MEGA_TheaterLocationCode
+
'&playDe='
+
MEGA_date
;
megabox
.
using_PlayingMovieURL
(
MEGA_PlayingMovieURL
);
await
megabox
.
geting_PlayingMovie
();
console
.
log
(
MEGA_PlayingMovieURL
,
megabox
.
movie_data
);
MEGA_flag
=
4
;
}
//원본 코드
// MEGA_date = parseInt(eventObj.message.text);
// if (MEGA_date && MEGA_TheaterLocationCode) {
// MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1=' + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
// console.log(MEGA_PlayingMovieURL)
// async.waterfall[
// megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL),
// megabox.geting_PlayingMovie()
// ]
// MEGA_flag++
// console.log(MEGA_flag);
// }
}
if
(
MEGA_flag
==
4
)
{
let
obj
=
{};
let
n
;
let
PlayingMovie
=
"-현재 상영작-\n\n"
;
let
movietitle
;
console
.
log
(
megabox
.
movie_data
);
for
(
n
=
0
;
n
<
Object
.
keys
(
megabox
.
movie_data
).
length
;
n
++
)
{
if
(
megabox
.
movie_data
[
n
].
running
===
'Y'
)
{
for
(
n
=
0
;
n
<
Object
.
keys
(
megabox
.
movie_data
).
length
;
n
++
)
{
if
(
megabox
.
movie_data
[
n
].
running
==
'Y'
)
{
console
.
log
(
megabox
.
movie_data
[
n
]);
movietitle
=
megabox
.
movie_data
[
n
].
title
;
MEGA_PlayingMovieList
[
movietitle
]
=
megabox
.
movie_data
[
n
].
movie_num
;
}
}
console
.
log
(
MEGA_PlayingMovieList
);
if
(
MEGA_PlayingMovieList
.
length
==
0
){
SendMessage
(
eventObj
,
"현재상영작이 없습니다."
,
""
);
}
else
if
(
MEGA_PlayingMovieList
.
length
==
1
){
SendMessage
(
eventObj
,
MEGA_PlayingMovieList
[
0
],
""
);
}
else
{
console
.
log
(
Object
.
keys
(
megabox
.
movie_data
).
length
);
if
(
Object
.
keys
(
megabox
.
movie_data
).
length
==
0
)
{
PushMessage
(
"현재상영작이 없습니다."
,
"영화관 선택 단계로 이동합니다."
);
setTimeout
(
function
()
{
PushMessage
(
"영화관 위치를 입력해주세요"
,
"ex1)강남"
);
},
1000
);
MEGA_flag
=
1
;
}
else
if
(
Object
.
keys
(
MEGA_PlayingMovieList
).
length
==
1
)
{
PlayingMovie
+=
'1. '
+
Object
.
keys
(
MEGA_PlayingMovieList
)[
0
];
PushMessage
(
PlayingMovie
,
"바로 링크가 보내집니다."
);
MEGA_title
=
MEGA_PlayingMovieList
[
Object
.
keys
(
MEGA_PlayingMovieList
)[
0
]];
setTimeout
(
function
()
{
const
final_URL
=
"https://www.megabox.co.kr/booking?rpstMovieNo="
+
MEGA_title
+
"&brchNo1="
+
MEGA_TheaterLocationCode
+
'&playDe='
+
MEGA_date
;
console
.
log
(
final_URL
)
PushMessage
(
final_URL
,
"링크를 누르면 예매창으로 바로 이동합니다."
);
},
1000
);
setTimeout
(
function
()
{
initFlag
=
false
;
MEGA_flag
=
-
1
;
MEGA_PlayingMovieList
=
[];
PushSingleMessage
(
"원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요."
);
},
1000
);
}
else
{
let
index
=
0
;
for
(
let
playingmovie
=
0
;
playingmovie
<
Object
.
keys
(
MEGA_PlayingMovieList
).
length
;
playingmovie
++
)
{
PlayingMovie
+=
(
playingmovie
+
1
).
toString
()
+
'. '
+
Object
.
keys
(
MEGA_PlayingMovieList
)[
index
++
];
PlayingMovie
+=
"\n"
;
for
(
let
playingmovie
=
0
;
playingmovie
<
Object
.
keys
(
MEGA_PlayingMovieList
).
length
;
playingmovie
++
)
{
PlayingMovie
+=
(
playingmovie
+
1
).
toString
()
+
'. '
+
Object
.
keys
(
MEGA_PlayingMovieList
)[
index
++
];
PlayingMovie
+=
"\n"
;
}
console
.
log
(
PlayingMovie
);
PushMessage
(
eventObj
,
PlayingMovie
,
"예매할 영화 번호를 입력해주세요.\n ex)1 (영화 앞 숫자만 입력)"
);
await
PushMessage
(
PlayingMovie
,
"예매할 영화 번호를 입력해주세요.\n ex)1 (영화 앞 숫자만 입력)"
);
MEGA_flag
=
5
;
}
MEGA_flag
++
;
},
10000
);
}
if
(
MEGA_flag
===
5
){
const
index
=
parseInt
(
message
.
text
)
-
1
;
MEGA_title
=
MEGA_PlayingMovieList
[
Object
.
keys
(
MEGA_PlayingMovieList
)[
index
]]
const
final_URL
=
"https://www.megabox.co.kr/booking?rpstMovieNo="
+
MEGA_title
+
"&brchNo1="
+
MEGA_TheaterLocation
+
'&playDe='
+
MEGA_date
;
console
.
log
(
final_URL
)
PushMessage
(
eventObj
,
final_URL
,
"예매창으로 바로 이동합니다."
);
}
else
if
(
MEGA_flag
==
5
)
{
const
index
=
parseInt
(
message
.
text
)
-
1
;
MEGA_title
=
MEGA_PlayingMovieList
[
Object
.
keys
(
MEGA_PlayingMovieList
)[
index
]];
const
final_URL
=
"https://www.megabox.co.kr/booking?rpstMovieNo="
+
MEGA_title
+
"&brchNo1="
+
MEGA_TheaterLocationCode
+
'&playDe='
+
MEGA_date
;
console
.
log
(
final_URL
);
PushMessage
(
final_URL
,
"링크를 누르면 예매창으로 바로 이동합니다."
);
setTimeout
(
function
()
{
MEGA_PlayingMovieList
=
[];
initFlag
=
false
;
MEGA_flag
=
-
1
;
PushSingleMessage
(
"원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요."
);
},
1000
);
}
}
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
(),
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
}
`
);
console
.
log
(
`[HTTPS] Server is started on port
${
sslport
}
`
);
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
}
//메세지 전송하는 function 모음
function
SendMessage
(
eventObj
,
text1
,
text2
=
""
)
{
//reply message
request
.
post
(
{
url
:
REPLY_TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
text1
},
{
"type"
:
"text"
,
"text"
:
text2
}
]
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
);
});
}
function
PushMessage
(
text1
,
text2
=
""
)
{
//push two message
request
.
post
(
{
url
:
PUSH_TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"to"
:
`
${
USER_ID
}
`
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
text1
},
{
"type"
:
"text"
,
"text"
:
text2
}
]
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
function
PushSingleMessage
(
text1
)
{
//push single message
request
.
post
(
{
url
:
PUSH_TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"to"
:
`
${
USER_ID
}
`
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
text1
}
]
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
\ No newline at end of file
...
...
Chatbot/package.json
View file @
b8a28b4
...
...
@@ -15,6 +15,7 @@
"cheerio"
:
"^1.0.0-rc.11"
,
"chromedriver"
:
"^101.0.0"
,
"express"
:
"^4.18.1"
,
"express-async-handler"
:
"^1.2.0"
,
"puppeteer"
:
"^14.1.1"
,
"selenium-webdriver"
:
"^4.1.2"
}
...
...
Please
register
or
login
to post a comment