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