Showing
4 changed files
with
124 additions
and
0 deletions
MovieInfo.js
0 → 100644
1 | +//============================================================= | ||
2 | +var express = require('express'); | ||
3 | +const request = require('request'); | ||
4 | +const config = require('/config.json'); | ||
5 | +//============================================================= | ||
6 | +const LINE_URL = 'https://api.line.me/v2/bot/message/reply' | ||
7 | +const TOKEN = config.TOKEN; | ||
8 | +const KOFIC_URL = 'http://www.kobis.or.kr/kobisopenapi/webservice/rest' | ||
9 | +const KOFIC_KEY = config.KOFIC_KEY; | ||
10 | +//============================================================= | ||
11 | + | ||
12 | +exports.MovieInfo = function(replyToken, message) { | ||
13 | + request.get( | ||
14 | + { | ||
15 | + url: KOFIC_URL+`/movie/searchMovieInfo.json?key=${KOFIC_KEY}&movieCd=${message}`, | ||
16 | + json:true | ||
17 | + },(error, response, body) => { | ||
18 | + if(!error && response.statusCode == 200) { | ||
19 | + console.log(body.movieInfoResult); | ||
20 | + var MovieInfo = body.movieInfoResult.movieInfo; | ||
21 | + var MovieName = MovieInfo.movieNm; | ||
22 | + var MovieDate = `${MovieInfo.openDt.slice(0,4)}년 ${MovieInfo.openDt.slice(4,6)}월 ${MovieInfo.openDt.slice(6,8)}일`; | ||
23 | + var MovieTime = MovieInfo.showTm; | ||
24 | + var MovieGenres = []; | ||
25 | + for(var i in MovieInfo.genres) | ||
26 | + { | ||
27 | + MovieGenres.push(MovieInfo.genres[i].genreNm); | ||
28 | + } | ||
29 | + var MovieDirec = MovieInfo.directors[0].peopleNm; | ||
30 | + var MovieActors = []; | ||
31 | + for(var i=0; i<MovieInfo.actors.length && i<5; i++) | ||
32 | + { | ||
33 | + MovieActors[i] = MovieInfo.actors[i].peopleNm; | ||
34 | + } | ||
35 | + | ||
36 | + request.post( | ||
37 | + { | ||
38 | + url: LINE_URL, | ||
39 | + headers: { | ||
40 | + 'Authorization': `Bearer ${TOKEN}` | ||
41 | + }, | ||
42 | + json: { | ||
43 | + "replyToken":replyToken, | ||
44 | + "messages":[ | ||
45 | + { | ||
46 | + "type":"text", | ||
47 | + "text":`영화명: ${MovieName}\n개봉날짜: ${MovieDate}\n상영시간: ${MovieTime}분\n장르: ${MovieGenres}\n감독: ${MovieDirec}\n출연배우: ${MovieActors}` | ||
48 | + } | ||
49 | + ] | ||
50 | + } | ||
51 | + },(error, response, body) => { | ||
52 | + console.log(body) | ||
53 | + }); | ||
54 | + } | ||
55 | + }); | ||
56 | +} |
MovieList.js
0 → 100644
1 | +var express = require('express'); | ||
2 | +const request = require('request'); | ||
3 | +var config = require('/config.json'); | ||
4 | +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
5 | +const TOKEN = config.TOKEN; | ||
6 | +const KOFIC_URL = 'http://www.kobis.or.kr/kobisopenapi/webservice/rest' | ||
7 | + | ||
8 | +//Enter a movie title in the message variable. | ||
9 | +//It will then return the movie title, director, and actor information to Line Messenger. | ||
10 | +exports.movielist = function (replyToken, message) { | ||
11 | + var encodedMessage = encodeURI(message); | ||
12 | + request.get( | ||
13 | + { | ||
14 | + url: KOFIC_URL+`/movie/searchMovieList.json?key=${config.KOFIC_KEY}&movieNm=${encodedMessage}`, | ||
15 | + json:true | ||
16 | + },(error, response, body) => { | ||
17 | + if(!error && response.statusCode == 200) { | ||
18 | + console.log(body.message); | ||
19 | + var result = '', movieNm, prdtYear, directors; | ||
20 | + for (let i = 0; i < body.movieListResult.movieList.length; i ++){ | ||
21 | + movieNm = body.movieListResult.movieList[i].movieNm; | ||
22 | + prdtYear = body.movieListResult.movieList[i].prdtYear; | ||
23 | + movieCd = body.movieListResult.movieList[i].movieCd; | ||
24 | + if(body.movieListResult.movieList[i].directors.length === 0){ | ||
25 | + directors = "감독정보없음" | ||
26 | + } | ||
27 | + else{ | ||
28 | + directors = body.movieListResult.movieList[i].directors[0].peopleNm; | ||
29 | + } | ||
30 | + result += '제목: ' + movieNm + `(${prdtYear})` + '\n' + '감독: ' + directors + '\n' + '영화코드: ' + movieCd + '\n'; | ||
31 | + } | ||
32 | + request.post( | ||
33 | + { | ||
34 | + url: TARGET_URL, | ||
35 | + headers: { | ||
36 | + 'Authorization': `Bearer ${TOKEN}` | ||
37 | + }, | ||
38 | + json: { | ||
39 | + "replyToken":replyToken, | ||
40 | + "messages":[ | ||
41 | + { | ||
42 | + "type":"text", | ||
43 | + "text":result | ||
44 | + } | ||
45 | + ] | ||
46 | + } | ||
47 | + },(error, response, body) => { | ||
48 | + console.log(body) | ||
49 | + }); | ||
50 | + } | ||
51 | + }); | ||
52 | + | ||
53 | +} |
package-lock.json
0 → 100644
This diff is collapsed. Click to expand it.
package.json
0 → 100644
1 | +{ | ||
2 | + "name": "trans", | ||
3 | + "version": "1.0.0", | ||
4 | + "description": "", | ||
5 | + "main": "app.js", | ||
6 | + "scripts": { | ||
7 | + "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | + }, | ||
9 | + "author": "", | ||
10 | + "license": "ISC", | ||
11 | + "dependencies": { | ||
12 | + "express": "^4.17.1", | ||
13 | + "request": "^2.88.2" | ||
14 | + } | ||
15 | +} |
-
Please register or login to post a comment