Merge branch 'feature/MovieRecommend'(for version 1.0)
Showing
2 changed files
with
34 additions
and
28 deletions
... | @@ -3,24 +3,23 @@ var express = require('express'); | ... | @@ -3,24 +3,23 @@ var express = require('express'); |
3 | const request = require('request'); | 3 | const request = require('request'); |
4 | const config = require('./config.json'); | 4 | const config = require('./config.json'); |
5 | //============================================================= | 5 | //============================================================= |
6 | -const LINE_URL = 'https://api.line.me/v2/bot/message/reply'; | 6 | +const LINE_REPLY_URL = 'https://api.line.me/v2/bot/message/reply' |
7 | const TOKEN = config.TOKEN; | 7 | const TOKEN = config.TOKEN; |
8 | -const KOFIC_URL = 'http://www.kobis.or.kr/kobisopenapi/webservice/rest'; | 8 | +const KOFIC_URL = 'http://www.kobis.or.kr/kobisopenapi/webservice/rest' |
9 | const KOFIC_KEY = config.KOFIC_KEY; | 9 | const KOFIC_KEY = config.KOFIC_KEY; |
10 | //============================================================= | 10 | //============================================================= |
11 | 11 | ||
12 | // 어제 기준 영화 순위(1위 ~ 5위) 출력 | 12 | // 어제 기준 영화 순위(1위 ~ 5위) 출력 |
13 | -exports.ShowYesterdayRank = function(replyToken) { | 13 | +exports.ShowYesterdayRank = function (replyToken) { |
14 | 14 | ||
15 | var yesterday = exports.GetYesterday(); | 15 | var yesterday = exports.GetYesterday(); |
16 | 16 | ||
17 | request.get( | 17 | request.get( |
18 | { | 18 | { |
19 | - url: KOFIC_URL+`/boxoffice/searchDailyBoxOfficeList.json?key=${KOFIC_KEY}&targetDt=${yesterday}`, | 19 | + url: KOFIC_URL + `/boxoffice/searchDailyBoxOfficeList.json?key=${KOFIC_KEY}&targetDt=${yesterday}`, |
20 | - json:true | 20 | + json: true |
21 | - },(error, response, body) => { | 21 | + }, (error, response, body) => { |
22 | - if(!error && response.statusCode == 200) { | 22 | + if (!error && response.statusCode == 200) { |
23 | - console.log(body.boxOfficeResult); | ||
24 | 23 | ||
25 | var movieName = []; | 24 | var movieName = []; |
26 | movieName[0] = body.boxOfficeResult.dailyBoxOfficeList[0].movieNm; | 25 | movieName[0] = body.boxOfficeResult.dailyBoxOfficeList[0].movieNm; |
... | @@ -43,27 +42,35 @@ exports.ShowYesterdayRank = function(replyToken) { | ... | @@ -43,27 +42,35 @@ exports.ShowYesterdayRank = function(replyToken) { |
43 | movieAudiAcc[3] = exports.numberWithCommas(body.boxOfficeResult.dailyBoxOfficeList[3].audiAcc); | 42 | movieAudiAcc[3] = exports.numberWithCommas(body.boxOfficeResult.dailyBoxOfficeList[3].audiAcc); |
44 | movieAudiAcc[4] = exports.numberWithCommas(body.boxOfficeResult.dailyBoxOfficeList[4].audiAcc); | 43 | movieAudiAcc[4] = exports.numberWithCommas(body.boxOfficeResult.dailyBoxOfficeList[4].audiAcc); |
45 | 44 | ||
45 | + var movieCode = []; | ||
46 | + movieCode[0] = body.boxOfficeResult.dailyBoxOfficeList[0].movieCd; | ||
47 | + movieCode[1] = body.boxOfficeResult.dailyBoxOfficeList[1].movieCd; | ||
48 | + movieCode[2] = body.boxOfficeResult.dailyBoxOfficeList[2].movieCd; | ||
49 | + movieCode[3] = body.boxOfficeResult.dailyBoxOfficeList[3].movieCd; | ||
50 | + movieCode[4] = body.boxOfficeResult.dailyBoxOfficeList[4].movieCd; | ||
51 | + | ||
46 | request.post( | 52 | request.post( |
47 | { | 53 | { |
48 | - url: LINE_URL, | 54 | + url: LINE_REPLY_URL, |
49 | headers: { | 55 | headers: { |
50 | 'Authorization': `Bearer ${TOKEN}` | 56 | 'Authorization': `Bearer ${TOKEN}` |
51 | }, | 57 | }, |
52 | json: { | 58 | json: { |
53 | - "replyToken":replyToken, | 59 | + "replyToken": replyToken, |
54 | - "messages":[ | 60 | + "messages": [ |
55 | { | 61 | { |
56 | - "type":"text", | 62 | + "type": "text", |
57 | "text": | 63 | "text": |
58 | - `[1위]\n영화제목 : ${movieName[0]}\n개봉일 : ${movieOpenDt[0]}\n누적 관객 수 : ${movieAudiAcc[0]}명\n\n`+ | 64 | + `[1위]\n영화제목 : ${movieName[0]}\n개봉일 : ${movieOpenDt[0]}\n누적 관객 수 : ${movieAudiAcc[0]}명\n영화코드 : ${movieCode[0]}\n\n` + |
59 | - `[2위]\n영화제목 : ${movieName[1]}\n개봉일 : ${movieOpenDt[1]}\n누적 관객 수 : ${movieAudiAcc[1]}명\n\n`+ | 65 | + `[2위]\n영화제목 : ${movieName[1]}\n개봉일 : ${movieOpenDt[1]}\n누적 관객 수 : ${movieAudiAcc[1]}명\n영화코드 : ${movieCode[1]}\n\n` + |
60 | - `[3위]\n영화제목 : ${movieName[2]}\n개봉일 : ${movieOpenDt[2]}\n누적 관객 수 : ${movieAudiAcc[2]}명\n\n`+ | 66 | + `[3위]\n영화제목 : ${movieName[2]}\n개봉일 : ${movieOpenDt[2]}\n누적 관객 수 : ${movieAudiAcc[2]}명\n영화코드 : ${movieCode[2]}\n\n` + |
61 | - `[4위]\n영화제목 : ${movieName[3]}\n개봉일 : ${movieOpenDt[3]}\n누적 관객 수 : ${movieAudiAcc[3]}명\n\n`+ | 67 | + `[4위]\n영화제목 : ${movieName[3]}\n개봉일 : ${movieOpenDt[3]}\n누적 관객 수 : ${movieAudiAcc[3]}명\n영화코드 : ${movieCode[3]}\n\n` + |
62 | - `[5위]\n영화제목 : ${movieName[4]}\n개봉일 : ${movieOpenDt[4]}\n누적 관객 수 : ${movieAudiAcc[4]}명\n\n` | 68 | + `[5위]\n영화제목 : ${movieName[4]}\n개봉일 : ${movieOpenDt[4]}\n누적 관객 수 : ${movieAudiAcc[4]}명\n영화코드 : ${movieCode[4]}\n\n` + |
69 | + `영화 상세 정보를 조회하시려면, 영화코드를 입력해주세요.` | ||
63 | } | 70 | } |
64 | ] | 71 | ] |
65 | } | 72 | } |
66 | - },(error, response, body) => { | 73 | + }, (error, response, body) => { |
67 | console.log(body) | 74 | console.log(body) |
68 | }); | 75 | }); |
69 | } | 76 | } |
... | @@ -72,7 +79,7 @@ exports.ShowYesterdayRank = function(replyToken) { | ... | @@ -72,7 +79,7 @@ exports.ShowYesterdayRank = function(replyToken) { |
72 | 79 | ||
73 | 80 | ||
74 | // 어제 날짜를 YYYYMMDD 형식(type: string)으로 반환하는 함수 | 81 | // 어제 날짜를 YYYYMMDD 형식(type: string)으로 반환하는 함수 |
75 | -exports.GetYesterday = function() { | 82 | +exports.GetYesterday = function () { |
76 | 83 | ||
77 | var today = new Date(); | 84 | var today = new Date(); |
78 | var yesterday = new Date(today.setDate(today.getDate() - 1)); | 85 | var yesterday = new Date(today.setDate(today.getDate() - 1)); |
... | @@ -86,6 +93,6 @@ exports.GetYesterday = function() { | ... | @@ -86,6 +93,6 @@ exports.GetYesterday = function() { |
86 | 93 | ||
87 | 94 | ||
88 | // 숫자 사이에 콤마(,) 찍고 반환하는 함수(입력, 출력 모두 문자열) | 95 | // 숫자 사이에 콤마(,) 찍고 반환하는 함수(입력, 출력 모두 문자열) |
89 | -exports.numberWithCommas = function(x) { | 96 | +exports.numberWithCommas = function (x) { |
90 | return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | 97 | return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); |
91 | } | 98 | } | ... | ... |
... | @@ -2,7 +2,6 @@ | ... | @@ -2,7 +2,6 @@ |
2 | var express = require('express'); | 2 | var express = require('express'); |
3 | const request = require('request'); | 3 | const request = require('request'); |
4 | const config = require('./config.json'); | 4 | const config = require('./config.json'); |
5 | -const dailyBoxOfficeList = require('./DailyBoxOfficeList.js'); | ||
6 | //============================================================= | 5 | //============================================================= |
7 | const LINE_URL = 'https://api.line.me/v2/bot/message/reply' | 6 | const LINE_URL = 'https://api.line.me/v2/bot/message/reply' |
8 | const TOKEN = config.TOKEN; | 7 | const TOKEN = config.TOKEN; |
... | @@ -28,7 +27,7 @@ app.post('/hook', function (req, res) { | ... | @@ -28,7 +27,7 @@ app.post('/hook', function (req, res) { |
28 | var eventObj = req.body.events[0]; | 27 | var eventObj = req.body.events[0]; |
29 | 28 | ||
30 | // console.log for debugging | 29 | // console.log for debugging |
31 | - console.log('======================', new Date() ,'======================'); | 30 | + console.log('======================', new Date(), '======================'); |
32 | console.log('[request]', req.body); | 31 | console.log('[request]', req.body); |
33 | console.log('[request source] ', eventObj.source); | 32 | console.log('[request source] ', eventObj.source); |
34 | console.log('[request message]', eventObj.message); | 33 | console.log('[request message]', eventObj.message); |
... | @@ -40,15 +39,15 @@ app.post('/hook', function (req, res) { | ... | @@ -40,15 +39,15 @@ app.post('/hook', function (req, res) { |
40 | 39 | ||
41 | 40 | ||
42 | // RESPONSE TO MESSAGE | 41 | // RESPONSE TO MESSAGE |
43 | -function Response(replyToken, message){ | 42 | +function Response(replyToken, message) { |
44 | // 사용자가 보낸 라인 메시지 문자열 안에 특정 문자열이 있으면, 특정 함수 실행 | 43 | // 사용자가 보낸 라인 메시지 문자열 안에 특정 문자열이 있으면, 특정 함수 실행 |
45 | - if(message.includes('최신') || message.includes('순위') || message.includes('오늘') || message.includes('추천')) { | 44 | + if (message.includes('최신') || message.includes('순위') || message.includes('오늘') || message.includes('추천')) { |
46 | BoxOffice.ShowYesterdayRank(replyToken); | 45 | BoxOffice.ShowYesterdayRank(replyToken); |
47 | } else if (isNaN(message) === false && message.length === 8) { | 46 | } else if (isNaN(message) === false && message.length === 8) { |
48 | // (예시) 영화 줄거리 출력 | 47 | // (예시) 영화 줄거리 출력 |
49 | MovieInfo.MovieInfo(replyToken, message); | 48 | MovieInfo.MovieInfo(replyToken, message); |
50 | } | 49 | } |
51 | - else if (typeof(message) === 'string') { | 50 | + else if (typeof (message) === 'string') { |
52 | // (예시) 영화 목록 출력 | 51 | // (예시) 영화 목록 출력 |
53 | MovieList.movielist(replyToken, message); | 52 | MovieList.movielist(replyToken, message); |
54 | } | 53 | } |
... | @@ -58,9 +57,9 @@ function Response(replyToken, message){ | ... | @@ -58,9 +57,9 @@ function Response(replyToken, message){ |
58 | // ※ WARNING: DO NOT TOUCH THIS CODE SECTION ※ | 57 | // ※ WARNING: DO NOT TOUCH THIS CODE SECTION ※ |
59 | try { | 58 | try { |
60 | const option = { | 59 | const option = { |
61 | - ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 60 | + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'), |
62 | - key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), | 61 | + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(), |
63 | - cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | 62 | + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(), |
64 | }; | 63 | }; |
65 | 64 | ||
66 | HTTPS.createServer(option, app).listen(sslport, () => { | 65 | HTTPS.createServer(option, app).listen(sslport, () => { | ... | ... |
-
Please register or login to post a comment