Showing
2 changed files
with
78 additions
and
82 deletions
... | @@ -19,7 +19,7 @@ app.use(bodyParser.urlencoded({ extended: false })); | ... | @@ -19,7 +19,7 @@ app.use(bodyParser.urlencoded({ extended: false })); |
19 | app.use(bodyParser.json()); | 19 | app.use(bodyParser.json()); |
20 | 20 | ||
21 | 21 | ||
22 | -const booking_url = "https://megabox.co.kr/booking"; | 22 | +const booking_url = "https://megabox.co.kr/booking?"; |
23 | exports.booking_url = booking_url; | 23 | exports.booking_url = booking_url; |
24 | const rate_url = "https://www.megabox.co.kr/movie"; | 24 | const rate_url = "https://www.megabox.co.kr/movie"; |
25 | 25 | ||
... | @@ -33,6 +33,7 @@ let index = 0; | ... | @@ -33,6 +33,7 @@ let index = 0; |
33 | 33 | ||
34 | exports.init = ()=>{async.waterfall([//for 동기적 처리 | 34 | exports.init = ()=>{async.waterfall([//for 동기적 처리 |
35 | async () => { | 35 | async () => { |
36 | + | ||
36 | const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();// | 37 | const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();// |
37 | driver.get(booking_url); | 38 | driver.get(booking_url); |
38 | driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 | 39 | driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴 |
... | @@ -55,8 +56,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 | ... | @@ -55,8 +56,7 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 |
55 | // let location_num = await item.getAttribute("brch-no"); | 56 | // let location_num = await item.getAttribute("brch-no"); |
56 | // let obj = {}; | 57 | // let obj = {}; |
57 | // obj[location_name]= location_num | 58 | // obj[location_name]= location_num |
58 | - // location_data[index++] = obj; | 59 | + // location_data[index++] = obj; |
59 | - | ||
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
... | @@ -108,30 +108,17 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 | ... | @@ -108,30 +108,17 @@ exports.init = ()=>{async.waterfall([//for 동기적 처리 |
108 | 108 | ||
109 | 109 | ||
110 | const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build(); | 110 | const appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build(); |
111 | -let PlayingMovieList = []; | ||
112 | -exports.PlayingMovieList = PlayingMovieList; | ||
113 | 111 | ||
114 | -exports.using_PlayingMovieURL = function(PlayingMovieURL){ | 112 | +exports.using_PlayingMovieURL = async(PlayingMovieURL) => { |
115 | - async( )=>{ | ||
116 | appdriver.get(PlayingMovieURL); | 113 | appdriver.get(PlayingMovieURL); |
117 | - appdriver.switchTo().frame(0) | 114 | + //appdriver.switchTo().frame(0) |
118 | - }//frameBokdMBooking 프레임 가져옴 | 115 | + //frameBokdMBooking 프레임 가져옴 |
119 | } | 116 | } |
120 | -exports.geting_PlayingMovie= function(){ | 117 | +exports.geting_PlayingMovie= async() => { |
121 | - async( )=>{ | 118 | + let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); |
122 | - let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn'))); | 119 | + let n = 0; |
123 | - let n = 0; | 120 | + for (item of movie_list) { |
124 | - for (item of movie_list) { | 121 | + movie_data[n++]['running'] = await item.getAttribute('form-at') |
125 | - let play = await item.getAttribute('form-at') | ||
126 | - let title = await item.getAttribute("movie-nm"); | ||
127 | - if(play ==='y' ){ | ||
128 | - PlayingMovieList[n++] = { | ||
129 | - title : await item.getAttribute("movie-no") | ||
130 | - } | ||
131 | - } | ||
132 | - | ||
133 | - } | ||
134 | - console.log(PlayingMovieList); | ||
135 | } | 122 | } |
136 | 123 | ||
137 | } | 124 | } | ... | ... |
1 | let megabox = require('./Megabox.js'); | 1 | let megabox = require('./Megabox.js'); |
2 | const async = require('async') | 2 | const async = require('async') |
3 | +//let SearchingTheaterAPI = require('./SearchingTheaterAPI'); | ||
4 | + | ||
3 | megabox.init(); | 5 | megabox.init(); |
4 | 6 | ||
5 | const request = require('request'); | 7 | const request = require('request'); |
... | @@ -15,12 +17,42 @@ const bodyParser = require('body-parser'); | ... | @@ -15,12 +17,42 @@ const bodyParser = require('body-parser'); |
15 | var app = express(); | 17 | var app = express(); |
16 | app.use(bodyParser.json()); | 18 | app.use(bodyParser.json()); |
17 | 19 | ||
20 | +const moment = require("moment"); | ||
21 | + | ||
18 | let MEGA_date; | 22 | let MEGA_date; |
19 | let MEGA_TheaterLocation; | 23 | let MEGA_TheaterLocation; |
20 | let MEGA_title; | 24 | let MEGA_title; |
21 | let MEGA_PlayingMovieURL; | 25 | let MEGA_PlayingMovieURL; |
22 | exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL; | 26 | exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL; |
23 | 27 | ||
28 | +let MEGA_flag = 0; | ||
29 | + | ||
30 | +function SendMessage(eventObj, text1, text2 = ""){ | ||
31 | + request.post( | ||
32 | + { | ||
33 | + url: REPLY_TARGET_URL, | ||
34 | + headers: { | ||
35 | + 'Authorization': `Bearer ${REPLY_TOKEN}` | ||
36 | + }, | ||
37 | + json: { | ||
38 | + "replyToken":eventObj.replyToken, | ||
39 | + "messages":[ | ||
40 | + { | ||
41 | + "type":"text", | ||
42 | + "text":text1 | ||
43 | + }, | ||
44 | + { | ||
45 | + "type":"text", | ||
46 | + "text":text2 | ||
47 | + } | ||
48 | + ] | ||
49 | + } | ||
50 | + | ||
51 | + },(error, response, body) => { | ||
52 | + //console.log(body) | ||
53 | + }); | ||
54 | +} | ||
55 | + | ||
24 | app.post('/hook', function (req, res) { | 56 | app.post('/hook', function (req, res) { |
25 | 57 | ||
26 | var eventObj = req.body.events[0]; | 58 | var eventObj = req.body.events[0]; |
... | @@ -33,75 +65,52 @@ app.post('/hook', function (req, res) { | ... | @@ -33,75 +65,52 @@ app.post('/hook', function (req, res) { |
33 | console.log('[request source] ', eventObj.source); | 65 | console.log('[request source] ', eventObj.source); |
34 | console.log('[request message]', eventObj.message); | 66 | console.log('[request message]', eventObj.message); |
35 | 67 | ||
36 | - if(eventObj.message.text == 3){ | 68 | + if(eventObj.message.text == 3 && MEGA_flag === 0){ |
37 | - request.post( | 69 | + const text1 = "영화관 위치를 입력해주세요"; |
38 | - { | 70 | + const text2 = "ex1)강남, ex2)강남시티"; |
39 | - url: REPLY_TARGET_URL, | 71 | + |
40 | - headers: { | 72 | + SendMessage(eventObj, text1, text2); |
41 | - 'Authorization': `Bearer ${REPLY_TOKEN}` | 73 | + MEGA_flag++; |
42 | - }, | 74 | + } |
43 | - json: { | 75 | + if(MEGA_flag===1){ |
44 | - "replyToken":eventObj.replyToken, | ||
45 | - "messages":[ | ||
46 | - { | ||
47 | - "type":"text", | ||
48 | - "text":"영화를 보실 날짜를 입력해주세요(잘못 입력하면 당일 날짜가 들어갑니다.)" | ||
49 | - }, | ||
50 | - { | ||
51 | - "type":"text", | ||
52 | - "text":"ex)20020409" | ||
53 | - } | ||
54 | - ] | ||
55 | - } | ||
56 | - | ||
57 | - },(error, response, body) => { | ||
58 | - console.log(body) | ||
59 | - }); | ||
60 | - | ||
61 | - } | ||
62 | - if(eventObj.message.text.length===8){ | ||
63 | - MEGA_date = parseInt(message.text); | ||
64 | - request.post( | ||
65 | - { | ||
66 | - url: REPLY_TARGET_URL, | ||
67 | - headers: { | ||
68 | - 'Authorization': `Bearer ${REPLY_TOKEN}` | ||
69 | - }, | ||
70 | - json: { | ||
71 | - "replyToken":eventObj.replyToken, | ||
72 | - "messages":[ | ||
73 | - { | ||
74 | - "type":"text", | ||
75 | - "text":"영화관 위치를 입력해주세요" | ||
76 | - }, | ||
77 | - { | ||
78 | - "type":"text", | ||
79 | - "text":"ex1)강남, ex2)강남시티" | ||
80 | - } | ||
81 | - ] | ||
82 | - } | ||
83 | - },(error, response, body) => { | ||
84 | - console.log(body) | ||
85 | - }); | ||
86 | - } | ||
87 | for(i of megabox.location_data){ | 76 | for(i of megabox.location_data){ |
88 | - if(i['LocationName'] == message.text){ | 77 | + |
78 | + if(i['LocationName'] === message.text){ | ||
89 | MEGA_TheaterLocation = i['LocationNUm']; | 79 | MEGA_TheaterLocation = i['LocationNUm']; |
90 | - console.log(MEGA_TheaterLocation) | 80 | + console.log(MEGA_TheaterLocation); |
81 | + MEGA_flag++; | ||
91 | break; | 82 | break; |
92 | } | 83 | } |
93 | } | 84 | } |
85 | + | ||
86 | + }else{ | ||
87 | + SendMessage(eventObj, "다시입력해주세요"); | ||
88 | + } | ||
89 | + | ||
90 | + if(MEGA_flag === 2){ | ||
91 | + MEGA_date = parseInt(message.text); | ||
92 | + const text1 = "영화를 보실 날짜를 입력해주세요."; | ||
93 | + const text2 = "ex)20020409"; | ||
94 | + | ||
95 | + SendMessage(eventObj, text1, text2); | ||
96 | + ++MEGA_flag; | ||
97 | + } | ||
98 | + | ||
99 | + if(moment(eventObj.message.text, "YYYYMMDD", true).isValid() && MEGA_flag===3){ | ||
100 | + console.log(3); | ||
94 | if(MEGA_date && MEGA_TheaterLocation){ | 101 | if(MEGA_date && MEGA_TheaterLocation){ |
95 | - MEGA_PlayingMovieURL = megabox.booking_url + '?brchNo1='+MEGA_TheaterLocation+'&playDe='+MEGA_date; | 102 | + MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1='+MEGA_TheaterLocation+'&playDe='+MEGA_date; |
96 | console.log(MEGA_PlayingMovieURL) | 103 | console.log(MEGA_PlayingMovieURL) |
97 | async.waterfall[ | 104 | async.waterfall[ |
98 | megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL), | 105 | megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL), |
99 | - megabox.geting_PlayingMovie(), | 106 | + megabox.geting_PlayingMovie() |
100 | - async()=>{console.log(megabox.PlayingMovieList)} | ||
101 | ] | 107 | ] |
102 | - | 108 | + MEGA_flag++ |
103 | } | 109 | } |
104 | - | 110 | + } |
111 | + if(MEGA_flag===4){ | ||
112 | + console.log(megabox.movie_data); | ||
113 | + } | ||
105 | res.sendStatus(200); | 114 | res.sendStatus(200); |
106 | 115 | ||
107 | }); | 116 | }); | ... | ... |
-
Please register or login to post a comment