이혜인

replying movie to play

...@@ -66,6 +66,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 ...@@ -66,6 +66,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
66 //Using getAttribute to get the data 66 //Using getAttribute to get the data
67 movie_data[r++] = { 67 movie_data[r++] = {
68 'rank' : r, 68 'rank' : r,
69 +
69 'title' : await item.getAttribute("movie-nm"), 70 'title' : await item.getAttribute("movie-nm"),
70 'movie_num':await item.getAttribute("movie-no"), 71 'movie_num':await item.getAttribute("movie-no"),
71 } 72 }
...@@ -100,7 +101,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 ...@@ -100,7 +101,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리
100 movie_data[r++]['rate'] = '예매율 0%'; 101 movie_data[r++]['rate'] = '예매율 0%';
101 } 102 }
102 } 103 }
103 - 104 + console.log("completed")
104 browser.close(); 105 browser.close();
105 }, 106 },
106 107
...@@ -120,54 +121,10 @@ exports.geting_PlayingMovie= async() => { ...@@ -120,54 +121,10 @@ exports.geting_PlayingMovie= async() => {
120 for (item of movie_list) { 121 for (item of movie_list) {
121 movie_data[n++]['running'] = await item.getAttribute('form-at') 122 movie_data[n++]['running'] = await item.getAttribute('form-at')
122 } 123 }
124 + console.log("completed")
123 125
124 } 126 }
125 127
126 -// let userData = {
127 -// 'Date': '',
128 -// 'location':''
129 -// };
130 -// // const _sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
131 -// app.get('/Megabox', (req, res) => {
132 -
133 -// res.send(movie_data);
134 -
135 -// })
136 -
137 -// app.post('/Megabox', (req, res) => {//사용자에게 Date와 location(영화관 장소) 받아옴
138 -// let PlayingMovieURL;
139 -// userData['Date'] = req.body.Date;
140 -// for(i of location_data){
141 -// if(i['LocationName'] == req.body.location){
142 -// userData['location']=i['LocationNUm'];
143 -// break;
144 -// }
145 -// }
146 -
147 -// PlayingMovieURL = booking_url + '?brchNo1='+userData['location']+'&playDe='+userData['Date'];//사용자 정보 바탕으로 해당 일자 영화관 영화 상영 여부 확인
148 -
149 -// appdriver.get(PlayingMovieURL);
150 -// appdriver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴
151 -// res.send(movie_data);
152 -
153 -// })
154 -// app.post('/Megabox', (req, res) => {//사용자에게 Date와 location(영화관 장소) 받아옴
155 -// userData['Date'] = req.body.Date;
156 -// for(i of location_data){
157 -// if(i['LocationName'] == req.body.location){
158 -// userData['location']=i['LocationNUm'];
159 -// break;
160 -// }
161 -// }
162 -
163 -// let PlayingMovieURL = booking_url + '?brchNo1='+userData['location']+'&playDe='+userData['Date'];//사용자 정보 바탕으로 해당 일자 영화관 영화 상영 여부 확인
164 -
165 -// appdriver.get(PlayingMovieURL);
166 -// appdriver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴
167 -// res.send(movie_data);
168 -
169 -// })
170 -
171 app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 여부 객체에 넣음 128 app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 여부 객체에 넣음
172 129
173 // let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); 130 // let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
...@@ -181,4 +138,4 @@ app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영 ...@@ -181,4 +138,4 @@ app.get('/Megabox/GetPlayingMovie', async(req, res, next) => {//영화 상영
181 res.send(PlayingMovieList); 138 res.send(PlayingMovieList);
182 }) 139 })
183 140
184 -app.listen(6000);
...\ No newline at end of file ...\ No newline at end of file
141 +app.listen(8000);
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -6,8 +6,11 @@ megabox.init(); ...@@ -6,8 +6,11 @@ megabox.init();
6 6
7 const request = require('request'); 7 const request = require('request');
8 var express = require('express'); 8 var express = require('express');
9 +const PUSH_TARGET_URL = 'https://api.line.me/v2/bot/message/push'
10 +const USER_ID = ''
11 +
9 const REPLY_TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 12 const REPLY_TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
10 -const REPLY_TOKEN = '' 13 +const TOKEN = ''
11 const fs = require('fs'); 14 const fs = require('fs');
12 const path = require('path'); 15 const path = require('path');
13 const HTTPS = require('https'); 16 const HTTPS = require('https');
...@@ -21,6 +24,7 @@ const moment = require("moment"); ...@@ -21,6 +24,7 @@ const moment = require("moment");
21 24
22 let MEGA_date; 25 let MEGA_date;
23 let MEGA_TheaterLocation; 26 let MEGA_TheaterLocation;
27 +let MEGA_PlayingMovieList = [];
24 let MEGA_title; 28 let MEGA_title;
25 let MEGA_PlayingMovieURL; 29 let MEGA_PlayingMovieURL;
26 exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL; 30 exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL;
...@@ -32,7 +36,7 @@ function SendMessage(eventObj, text1, text2 = ""){ ...@@ -32,7 +36,7 @@ function SendMessage(eventObj, text1, text2 = ""){
32 { 36 {
33 url: REPLY_TARGET_URL, 37 url: REPLY_TARGET_URL,
34 headers: { 38 headers: {
35 - 'Authorization': `Bearer ${REPLY_TOKEN}` 39 + 'Authorization': `Bearer ${TOKEN}`
36 }, 40 },
37 json: { 41 json: {
38 "replyToken":eventObj.replyToken, 42 "replyToken":eventObj.replyToken,
...@@ -49,11 +53,35 @@ function SendMessage(eventObj, text1, text2 = ""){ ...@@ -49,11 +53,35 @@ function SendMessage(eventObj, text1, text2 = ""){
49 } 53 }
50 54
51 },(error, response, body) => { 55 },(error, response, body) => {
52 - //console.log(body) 56 + console.log(body);
53 }); 57 });
54 } 58 }
59 +function PushMessage(eventObj, text1, text2 = ""){
60 +request.post(
61 + {
62 + url: PUSH_TARGET_URL,
63 + headers: {
64 + 'Authorization': `Bearer ${TOKEN}`
65 + },
66 + json: {
67 + "to": `${USER_ID}`,
68 + "messages":[
69 + {
70 + "type":"text",
71 + "text":text1
72 + },
73 + {
74 + "type":"text",
75 + "text":text2
76 + }
77 + ]
78 + }
79 + },(error, response, body) => {
80 + console.log(body)
81 + });
82 +}
55 83
56 -app.post('/hook', function (req, res) { 84 +app.post('/hook', (req, res) => {
57 85
58 var eventObj = req.body.events[0]; 86 var eventObj = req.body.events[0];
59 var source = eventObj.source; 87 var source = eventObj.source;
...@@ -64,40 +92,39 @@ app.post('/hook', function (req, res) { ...@@ -64,40 +92,39 @@ app.post('/hook', function (req, res) {
64 console.log('[request]', req.body); 92 console.log('[request]', req.body);
65 console.log('[request source] ', eventObj.source); 93 console.log('[request source] ', eventObj.source);
66 console.log('[request message]', eventObj.message); 94 console.log('[request message]', eventObj.message);
67 - 95 +
68 if(eventObj.message.text == 3 && MEGA_flag === 0){ 96 if(eventObj.message.text == 3 && MEGA_flag === 0){
69 const text1 = "영화관 위치를 입력해주세요"; 97 const text1 = "영화관 위치를 입력해주세요";
70 - const text2 = "ex1)강남, ex2)강남시티"; 98 + const text2 = "ex1)강남";
71 -
72 SendMessage(eventObj, text1, text2); 99 SendMessage(eventObj, text1, text2);
73 MEGA_flag++; 100 MEGA_flag++;
101 + console.log(MEGA_flag)
74 } 102 }
103 +
75 if(MEGA_flag===1){ 104 if(MEGA_flag===1){
105 + console.log(MEGA_flag);
76 for(i of megabox.location_data){ 106 for(i of megabox.location_data){
77 -
78 if(i['LocationName'] === message.text){ 107 if(i['LocationName'] === message.text){
79 MEGA_TheaterLocation = i['LocationNUm']; 108 MEGA_TheaterLocation = i['LocationNUm'];
80 console.log(MEGA_TheaterLocation); 109 console.log(MEGA_TheaterLocation);
81 MEGA_flag++; 110 MEGA_flag++;
111 + console.log(MEGA_flag)
82 break; 112 break;
83 } 113 }
84 } 114 }
85 -
86 - }else{
87 - SendMessage(eventObj, "다시입력해주세요");
88 } 115 }
89 116
90 if(MEGA_flag === 2){ 117 if(MEGA_flag === 2){
91 - MEGA_date = parseInt(message.text);
92 const text1 = "영화를 보실 날짜를 입력해주세요."; 118 const text1 = "영화를 보실 날짜를 입력해주세요.";
93 const text2 = "ex)20020409"; 119 const text2 = "ex)20020409";
94 -
95 SendMessage(eventObj, text1, text2); 120 SendMessage(eventObj, text1, text2);
96 ++MEGA_flag; 121 ++MEGA_flag;
97 } 122 }
98 123
99 - if(moment(eventObj.message.text, "YYYYMMDD", true).isValid() && MEGA_flag===3){ 124 + if(moment(eventObj.message.text, "YYYYMMDD", true).isValid() && MEGA_flag===3){
100 - console.log(3); 125 +
126 + MEGA_date = parseInt(eventObj.message.text);
127 +
101 if(MEGA_date && MEGA_TheaterLocation){ 128 if(MEGA_date && MEGA_TheaterLocation){
102 MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1='+MEGA_TheaterLocation+'&playDe='+MEGA_date; 129 MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1='+MEGA_TheaterLocation+'&playDe='+MEGA_date;
103 console.log(MEGA_PlayingMovieURL) 130 console.log(MEGA_PlayingMovieURL)
...@@ -106,11 +133,56 @@ app.post('/hook', function (req, res) { ...@@ -106,11 +133,56 @@ app.post('/hook', function (req, res) {
106 megabox.geting_PlayingMovie() 133 megabox.geting_PlayingMovie()
107 ] 134 ]
108 MEGA_flag++ 135 MEGA_flag++
136 + console.log(MEGA_flag);
109 } 137 }
110 - } 138 + }
139 +
111 if(MEGA_flag===4){ 140 if(MEGA_flag===4){
112 - console.log(megabox.movie_data); 141 + let index = 0;
113 - } 142 + let n;
143 + let PlayingMovie = "-현재 상영작-\n\n";
144 + const text1 = "현재상영작을 가져오는 중입니다.";
145 + const text2 = "잠시만 기다려주세요.";
146 + PushMessage(eventObj, text1, text2);
147 + setTimeout(function() {
148 +
149 + console.log(megabox.movie_data);
150 + for(n = 0; n<Object.keys(megabox.movie_data).length; n++){
151 + if(megabox.movie_data[n].running==='Y'){
152 + console.log(megabox.movie_data[n]);
153 + MEGA_PlayingMovieList[index++] = megabox.movie_data[n].title;
154 + }
155 + n++;
156 + }
157 +
158 + if(MEGA_PlayingMovieList.length == 0){
159 + SendMessage(eventObj, "현재상영작이 없습니다.","");
160 + }
161 + else if(MEGA_PlayingMovieList.length == 1){
162 + SendMessage(eventObj, MEGA_PlayingMovieList[0],"");
163 + }
164 + else{
165 + index = 0;
166 + for(let playingmovie = 0; playingmovie < MEGA_PlayingMovieList.length; playingmovie++)
167 + {
168 + PlayingMovie += (playingmovie+1).toString()+'. ' + MEGA_PlayingMovieList[playingmovie];
169 + PlayingMovie +="\n";
170 + }
171 +
172 + console.log(PlayingMovie);
173 + PushMessage(eventObj, PlayingMovie, "예매할 영화 번호를 입력해주세요.\n ex)1 (영화 앞 숫자만 입력)");
174 + }
175 +
176 + MEGA_flag++;
177 + },10000);
178 +
179 + }
180 + if(MEGA_flag===5){
181 + const index = parseInt(message.text) -1;
182 + //MEGA_title =
183 +
184 + }
185 +
114 res.sendStatus(200); 186 res.sendStatus(200);
115 187
116 }); 188 });
......