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-01 21:03:13 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7e1c5ffa23d004a5f200d14891e17f5fc651b259
7e1c5ffa
1 parent
64237373
Add functions(ClassifyMessage / GetYesterday)
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
11 deletions
DailyBoxOfficeList.js
DailyBoxOfficeList.js
View file @
7e1c5ff
...
...
@@ -23,6 +23,23 @@ app.use(bodyParser.json());
// ===============================================
// [MAIN] CLASSIFY THE MESSAGE
function
ClassifyMessage
(
replyToken
,
imessage
){
var
message
=
String
(
imessage
);
if
(
message
.
includes
(
'최신'
)
||
message
.
includes
(
'순위'
)
||
message
.
includes
(
'오늘'
))
{
showYesterdayRank
(
replyToken
);
}
else
if
(
message
.
includes
(
'줄거리'
))
{
// (예시) 영화 줄거리 출력
}
else
if
(
message
.
includes
(
'목록'
))
{
// (예시) 영화 목록 출력
}
}
// 사용자의 LINE message 수신
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
...
...
@@ -33,27 +50,29 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
showYesterdayRank
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
ClassifyMessage
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
res
.
sendStatus
(
200
);
});
// 해당 날짜 영화 순위 출력 함수
// 입력 인자 중 message 에는 어제 날짜 들어감(ex: 20220528)
function
showYesterdayRank
(
replyToken
,
message
)
{
// 한국영화진흥위원회 API는 get 형태로 호출
// 어제 영화 순위 1위 ~ 5위 출력
function
showYesterdayRank
(
replyToken
)
{
var
yesterday
=
GetYesterday
();
request
.
get
(
{
url
:
BOXOFFICE_URL
+
`?key=
${
KOFIC_KEY
}
&targetDt=
${
message
}
`
,
url
:
BOXOFFICE_URL
+
`?key=
${
KOFIC_KEY
}
&targetDt=
${
yesterday
}
`
,
json
:
true
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
console
.
log
(
body
.
boxOfficeResult
);
var
transMessage_1
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
0
].
movieNm
;
var
transMessage_2
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
1
].
movieNm
;
var
transMessage_3
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
2
].
movieNm
;
var
transMessage_4
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
3
].
movieNm
;
var
movie_1st
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
0
].
movieNm
;
var
movie_2nd
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
1
].
movieNm
;
var
movie_3rd
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
2
].
movieNm
;
var
movie_4th
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
3
].
movieNm
;
var
movie_5th
=
body
.
boxOfficeResult
.
dailyBoxOfficeList
[
4
].
movieNm
;
request
.
post
(
{
...
...
@@ -66,7 +85,12 @@ function showYesterdayRank(replyToken, message) {
"messages"
:[
{
"type"
:
"text"
,
"text"
:
`1위 :
${
transMessage_1
}
\n2위 :
${
transMessage_2
}
\n3위 :
${
transMessage_3
}
\n4위 :
${
transMessage_4
}
`
"text"
:
`1위 :
${
movie_1st
}
\n`
+
`2위 :
${
movie_2nd
}
\n`
+
`3위 :
${
movie_3rd
}
\n`
+
`4위 :
${
movie_4th
}
\n`
+
`5위 :
${
movie_5th
}
\n`
}
]
}
...
...
@@ -77,6 +101,22 @@ function showYesterdayRank(replyToken, message) {
});
}
// 어제 날짜를 YYYYMMDD 형식(type: string)으로 반환하는 함수
function
GetYesterday
()
{
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
);
}
// ※ WARNING: DO NOT TOUCH THIS CODE SECTION
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
...
...
Please
register
or
login
to post a comment