Toggle navigation
Toggle navigation
This project
Loading...
Sign in
백승욱
/
movie-reco-chatbot
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-06 11:55:08 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
271dc0617b5726bed6d6847d86a9e59a349148c8
271dc061
1 parent
b451de8f
Delete DailyBoxOfficeList.js for merging
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
102 deletions
DailyBoxOfficeList.js
main.js
DailyBoxOfficeList.js
deleted
100644 → 0
View file @
b451de8
//=============================================================
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
config
=
require
(
'./config.json'
);
//=============================================================
const
LINE_URL
=
'https://api.line.me/v2/bot/message/reply'
;
const
TOKEN
=
config
.
TOKEN
;
const
KOFIC_URL
=
'http://www.kobis.or.kr/kobisopenapi/webservice/rest'
;
const
KOFIC_KEY
=
config
.
KOFIC_KEY
;
//=============================================================
// 어제 기준 영화 순위(1위 ~ 5위) 출력
exports
.
ShowYesterdayRank
=
function
(
replyToken
)
{
var
yesterday
=
exports
.
GetYesterday
();
request
.
get
(
{
url
:
KOFIC_URL
+
`/boxoffice/searchDailyBoxOfficeList.json?key=
${
KOFIC_KEY
}
&targetDt=
${
yesterday
}
`
,
json
:
true
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
console
.
log
(
body
.
boxOfficeResult
);
var
movieName
=
[];
movieName
[
0
]
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
0
].
movieNm
;
movieName
[
1
]
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
1
].
movieNm
;
movieName
[
2
]
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
2
].
movieNm
;
movieName
[
3
]
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
3
].
movieNm
;
movieName
[
4
]
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
4
].
movieNm
;
var
movieOpenDt
=
[];
movieOpenDt
[
0
]
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
0
].
openDt
;
movieOpenDt
[
1
]
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
1
].
openDt
;
movieOpenDt
[
2
]
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
2
].
openDt
;
movieOpenDt
[
3
]
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
3
].
openDt
;
movieOpenDt
[
4
]
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
4
].
openDt
;
var
movieAudiAcc
=
[];
movieAudiAcc
[
0
]
=
exports
.
numberWithCommas
(
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
0
].
audiAcc
);
movieAudiAcc
[
1
]
=
exports
.
numberWithCommas
(
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
1
].
audiAcc
);
movieAudiAcc
[
2
]
=
exports
.
numberWithCommas
(
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
2
].
audiAcc
);
movieAudiAcc
[
3
]
=
exports
.
numberWithCommas
(
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
3
].
audiAcc
);
movieAudiAcc
[
4
]
=
exports
.
numberWithCommas
(
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
4
].
audiAcc
);
request
.
post
(
{
url
:
LINE_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
`[1위]\n영화제목 :
${
movieName
[
0
]}
\n개봉일 :
${
movieOpenDt
[
0
]}
\n누적 관객 수 :
${
movieAudiAcc
[
0
]}
명\n\n`
+
`[2위]\n영화제목 :
${
movieName
[
1
]}
\n개봉일 :
${
movieOpenDt
[
1
]}
\n누적 관객 수 :
${
movieAudiAcc
[
1
]}
명\n\n`
+
`[3위]\n영화제목 :
${
movieName
[
2
]}
\n개봉일 :
${
movieOpenDt
[
2
]}
\n누적 관객 수 :
${
movieAudiAcc
[
2
]}
명\n\n`
+
`[4위]\n영화제목 :
${
movieName
[
3
]}
\n개봉일 :
${
movieOpenDt
[
3
]}
\n누적 관객 수 :
${
movieAudiAcc
[
3
]}
명\n\n`
+
`[5위]\n영화제목 :
${
movieName
[
4
]}
\n개봉일 :
${
movieOpenDt
[
4
]}
\n누적 관객 수 :
${
movieAudiAcc
[
4
]}
명\n\n`
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
});
}
// 어제 날짜를 YYYYMMDD 형식(type: string)으로 반환하는 함수
exports
.
GetYesterday
=
function
()
{
var
today
=
new
Date
();
var
yesterday
=
new
Date
(
today
.
setDate
(
today
.
getDate
()
-
1
));
var
year
=
yesterday
.
getFullYear
();
var
month
=
(
'0'
+
(
yesterday
.
getMonth
()
+
1
)).
slice
(
-
2
);
var
day
=
(
'0'
+
yesterday
.
getDate
()).
slice
(
-
2
);
return
(
year
+
month
+
day
);
}
// 숫자 사이에 콤마(,) 찍고 반환하는 함수(입력, 출력 모두 문자열)
exports
.
numberWithCommas
=
function
(
x
)
{
return
x
.
toString
().
replace
(
/
\B(?=(\d{3})
+
(?!\d))
/g
,
","
);
}
main.js
View file @
271dc06
...
...
@@ -27,7 +27,7 @@ app.post('/hook', function (req, res) {
var
eventObj
=
req
.
body
.
events
[
0
];
// console.log for debugging
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
);
...
...
@@ -39,17 +39,17 @@ app.post('/hook', function (req, res) {
// RESPONSE TO MESSAGE
function
Response
(
replyToken
,
message
){
function
Response
(
replyToken
,
message
)
{
// 사용자가 보낸 라인 메시지 문자열 안에 특정 문자열이 있으면, 특정 함수 실행
if
(
message
.
includes
(
'최신'
)
||
message
.
includes
(
'순위'
)
||
message
.
includes
(
'오늘'
)
||
message
.
includes
(
'추천'
))
{
if
(
message
.
includes
(
'최신'
)
||
message
.
includes
(
'순위'
)
||
message
.
includes
(
'오늘'
)
||
message
.
includes
(
'추천'
))
{
BoxOffice
.
ShowYesterdayRank
(
replyToken
);
}
else
if
(
isNaN
(
message
)
===
false
&&
message
.
length
===
8
)
{
// (예시) 영화 줄거리 출력
MovieInfo
.
MovieInfo
(
replyToken
,
message
);
// (예시) 영화 줄거리 출력
MovieInfo
.
MovieInfo
(
replyToken
,
message
);
}
else
if
(
typeof
(
message
)
===
'string'
)
{
// (예시) 영화 목록 출력
MovieList
.
movielist
(
replyToken
,
message
);
else
if
(
typeof
(
message
)
===
'string'
)
{
// (예시) 영화 목록 출력
MovieList
.
movielist
(
replyToken
,
message
);
}
}
...
...
@@ -57,9 +57,9 @@ function Response(replyToken, message){
// ※ WARNING: DO NOT TOUCH THIS CODE SECTION ※
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
,
()
=>
{
...
...
Please
register
or
login
to post a comment