Showing
1 changed file
with
98 additions
and
0 deletions
DailyBoxOfficeList.js
0 → 100644
1 | +//============================================================= | ||
2 | +var express = require('express'); | ||
3 | +const request = require('request'); | ||
4 | +const config = require('./config.json'); | ||
5 | +//============================================================= | ||
6 | +const LINE_REPLY_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 | + | ||
24 | + var movieName = []; | ||
25 | + movieName[0] = body.boxOfficeResult.dailyBoxOfficeList[0].movieNm; | ||
26 | + movieName[1] = body.boxOfficeResult.dailyBoxOfficeList[1].movieNm; | ||
27 | + movieName[2] = body.boxOfficeResult.dailyBoxOfficeList[2].movieNm; | ||
28 | + movieName[3] = body.boxOfficeResult.dailyBoxOfficeList[3].movieNm; | ||
29 | + movieName[4] = body.boxOfficeResult.dailyBoxOfficeList[4].movieNm; | ||
30 | + | ||
31 | + var movieOpenDt = []; | ||
32 | + movieOpenDt[0] = body.boxOfficeResult.dailyBoxOfficeList[0].openDt; | ||
33 | + movieOpenDt[1] = body.boxOfficeResult.dailyBoxOfficeList[1].openDt; | ||
34 | + movieOpenDt[2] = body.boxOfficeResult.dailyBoxOfficeList[2].openDt; | ||
35 | + movieOpenDt[3] = body.boxOfficeResult.dailyBoxOfficeList[3].openDt; | ||
36 | + movieOpenDt[4] = body.boxOfficeResult.dailyBoxOfficeList[4].openDt; | ||
37 | + | ||
38 | + var movieAudiAcc = []; | ||
39 | + movieAudiAcc[0] = exports.numberWithCommas(body.boxOfficeResult.dailyBoxOfficeList[0].audiAcc); | ||
40 | + movieAudiAcc[1] = exports.numberWithCommas(body.boxOfficeResult.dailyBoxOfficeList[1].audiAcc); | ||
41 | + movieAudiAcc[2] = exports.numberWithCommas(body.boxOfficeResult.dailyBoxOfficeList[2].audiAcc); | ||
42 | + movieAudiAcc[3] = exports.numberWithCommas(body.boxOfficeResult.dailyBoxOfficeList[3].audiAcc); | ||
43 | + movieAudiAcc[4] = exports.numberWithCommas(body.boxOfficeResult.dailyBoxOfficeList[4].audiAcc); | ||
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 | + | ||
52 | + request.post( | ||
53 | + { | ||
54 | + url: LINE_REPLY_URL, | ||
55 | + headers: { | ||
56 | + 'Authorization': `Bearer ${TOKEN}` | ||
57 | + }, | ||
58 | + json: { | ||
59 | + "replyToken": replyToken, | ||
60 | + "messages": [ | ||
61 | + { | ||
62 | + "type": "text", | ||
63 | + "text": | ||
64 | + `[1위]\n영화제목 : ${movieName[0]}\n개봉일 : ${movieOpenDt[0]}\n누적 관객 수 : ${movieAudiAcc[0]}명\n영화코드 : ${movieCode[0]}\n\n` + | ||
65 | + `[2위]\n영화제목 : ${movieName[1]}\n개봉일 : ${movieOpenDt[1]}\n누적 관객 수 : ${movieAudiAcc[1]}명\n영화코드 : ${movieCode[1]}\n\n` + | ||
66 | + `[3위]\n영화제목 : ${movieName[2]}\n개봉일 : ${movieOpenDt[2]}\n누적 관객 수 : ${movieAudiAcc[2]}명\n영화코드 : ${movieCode[2]}\n\n` + | ||
67 | + `[4위]\n영화제목 : ${movieName[3]}\n개봉일 : ${movieOpenDt[3]}\n누적 관객 수 : ${movieAudiAcc[3]}명\n영화코드 : ${movieCode[3]}\n\n` + | ||
68 | + `[5위]\n영화제목 : ${movieName[4]}\n개봉일 : ${movieOpenDt[4]}\n누적 관객 수 : ${movieAudiAcc[4]}명\n영화코드 : ${movieCode[4]}\n\n` + | ||
69 | + `영화 상세 정보를 조회하시려면, 영화코드를 입력해주세요.` | ||
70 | + } | ||
71 | + ] | ||
72 | + } | ||
73 | + }, (error, response, body) => { | ||
74 | + console.log(body) | ||
75 | + }); | ||
76 | + } | ||
77 | + }); | ||
78 | +} | ||
79 | + | ||
80 | + | ||
81 | +// 어제 날짜를 YYYYMMDD 형식(type: string)으로 반환하는 함수 | ||
82 | +exports.GetYesterday = function () { | ||
83 | + | ||
84 | + var today = new Date(); | ||
85 | + var yesterday = new Date(today.setDate(today.getDate() - 1)); | ||
86 | + | ||
87 | + var year = yesterday.getFullYear(); | ||
88 | + var month = ('0' + (yesterday.getMonth() + 1)).slice(-2); | ||
89 | + var day = ('0' + yesterday.getDate()).slice(-2); | ||
90 | + | ||
91 | + return (year + month + day); | ||
92 | +} | ||
93 | + | ||
94 | + | ||
95 | +// 숫자 사이에 콤마(,) 찍고 반환하는 함수(입력, 출력 모두 문자열) | ||
96 | +exports.numberWithCommas = function (x) { | ||
97 | + return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | ||
98 | +} |
-
Please register or login to post a comment