MovieInfo.js
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//=============================================================
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;
//=============================================================
exports.MovieInfo = function(replyToken, message) {
request.get(
{
url: KOFIC_URL+`/movie/searchMovieInfo.json?key=${KOFIC_KEY}&movieCd=${message}`,
json:true
},(error, response, body) => {
if(!error && response.statusCode == 200) {
console.log(body.movieInfoResult);
var MovieInfo = body.movieInfoResult.movieInfo;
var MovieName = MovieInfo.movieNm;
var MovieDate = `${MovieInfo.openDt.slice(0,4)}년 ${MovieInfo.openDt.slice(4,6)}월 ${MovieInfo.openDt.slice(6,8)}일`;
var MovieTime = MovieInfo.showTm;
var MovieGenres = [];
for(var i in MovieInfo.genres)
{
MovieGenres.push(MovieInfo.genres[i].genreNm);
}
var MovieDirec = MovieInfo.directors[0].peopleNm;
var MovieActors = [];
for(var i=0; i<MovieInfo.actors.length && i<5; i++)
{
MovieActors[i] = MovieInfo.actors[i].peopleNm;
}
request.post(
{
url: LINE_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type":"text",
"text":`영화명: ${MovieName}\n개봉날짜: ${MovieDate}\n상영시간: ${MovieTime}분\n장르: ${MovieGenres}\n감독: ${MovieDirec}\n출연배우: ${MovieActors}`
}
]
}
},(error, response, body) => {
console.log(body)
});
}
});
}