Showing
1 changed file
with
56 additions
and
28 deletions
... | @@ -31,7 +31,7 @@ app.post('/hook', function (req, res) { | ... | @@ -31,7 +31,7 @@ app.post('/hook', function (req, res) { |
31 | return | 31 | return |
32 | } | 32 | } |
33 | var tempstockList = data.toString().split("\n"); // ex) stockList = [[012312 ~~],[123012 ~~],[192312 ~~],[192310 ~~],[...]] | 33 | var tempstockList = data.toString().split("\n"); // ex) stockList = [[012312 ~~],[123012 ~~],[192312 ~~],[192310 ~~],[...]] |
34 | - for (x in tempstockList){ | 34 | + for (i in tempstockList){ |
35 | var stockList = tempstockList[i].toString().split(" "); // ex) stockList = [[012312,~~],[1230012,~~],[1923,~~],[192310,~~],[...]] | 35 | var stockList = tempstockList[i].toString().split(" "); // ex) stockList = [[012312,~~],[1230012,~~],[1923,~~],[192310,~~],[...]] |
36 | } | 36 | } |
37 | // for (i in stockList) { | 37 | // for (i in stockList) { |
... | @@ -46,10 +46,11 @@ app.post('/hook', function (req, res) { | ... | @@ -46,10 +46,11 @@ app.post('/hook', function (req, res) { |
46 | console.log('[request message]', eventObj.message); | 46 | console.log('[request message]', eventObj.message); |
47 | 47 | ||
48 | var s_code = get_stock_code(stockList,stock_code,eventObj.replyToken,eventObj.message.text); | 48 | var s_code = get_stock_code(stockList,stock_code,eventObj.replyToken,eventObj.message.text); |
49 | - var wanted_price = get_wanted_price(eventObj.replyToken,eventObj.message.text); | 49 | + //var wanted_price = get_wanted_price(eventObj.replyToken,eventObj.message.text); |
50 | 50 | ||
51 | cron.schedule('*/5 * * * *', () => { | 51 | cron.schedule('*/5 * * * *', () => { |
52 | compare(s_code, wanted_price); | 52 | compare(s_code, wanted_price); |
53 | + console.log('It works') | ||
53 | }); | 54 | }); |
54 | 55 | ||
55 | 56 | ||
... | @@ -96,8 +97,35 @@ app.post('/hook', function (req, res) { | ... | @@ -96,8 +97,35 @@ app.post('/hook', function (req, res) { |
96 | }); | 97 | }); |
97 | 98 | ||
98 | function get_stock_code(stockList,stock_code,replyToken,message){ | 99 | function get_stock_code(stockList,stock_code,replyToken,message){ |
100 | + var temp = message.toString().split(" "); | ||
101 | + var wanted_stock_name = temp[0]; | ||
102 | + var wanted_stock_price = temp[1]; | ||
103 | + | ||
104 | + if (wanted_stock_price < 0){ | ||
105 | + request.post( | ||
106 | + { | ||
107 | + url: TARGET_URL, | ||
108 | + headers: { | ||
109 | + 'Authorization': `Bearer ${TOKEN}` | ||
110 | + }, | ||
111 | + json: { | ||
112 | + "replyToken":replyToken, | ||
113 | + "messages":[ | ||
114 | + { | ||
115 | + "type":"text", | ||
116 | + "text":"Price must be positive number" | ||
117 | + }, | ||
118 | + ] | ||
119 | + } | ||
120 | + },(error, response, body) => { | ||
121 | + console.log(body) | ||
122 | + }); | ||
123 | + | ||
124 | + } | ||
125 | + | ||
126 | + | ||
99 | for (let i = 0; i<stockList.length; i++) { | 127 | for (let i = 0; i<stockList.length; i++) { |
100 | - if (eventObj.message.text == stockList[i][1]){ // 입력한거 나오면 코드로 바꿔줌 | 128 | + if (wanted_stock_name == stockList[i][1]){ // 입력한거 나오면 코드로 바꿔줌 |
101 | stock_code = stockList[i][0] | 129 | stock_code = stockList[i][0] |
102 | return stock_code | 130 | return stock_code |
103 | } | 131 | } |
... | @@ -109,7 +137,7 @@ function get_stock_code(stockList,stock_code,replyToken,message){ | ... | @@ -109,7 +137,7 @@ function get_stock_code(stockList,stock_code,replyToken,message){ |
109 | 'Authorization': `Bearer ${TOKEN}` | 137 | 'Authorization': `Bearer ${TOKEN}` |
110 | }, | 138 | }, |
111 | json: { | 139 | json: { |
112 | - "replyToken":eventObj.replyToken, | 140 | + "replyToken":replyToken, |
113 | "messages":[ | 141 | "messages":[ |
114 | { | 142 | { |
115 | "type":"text", | 143 | "type":"text", |
... | @@ -125,29 +153,29 @@ function get_stock_code(stockList,stock_code,replyToken,message){ | ... | @@ -125,29 +153,29 @@ function get_stock_code(stockList,stock_code,replyToken,message){ |
125 | } | 153 | } |
126 | } | 154 | } |
127 | 155 | ||
128 | -function get_wanted_price(replyToken,message){ | 156 | +// function get_wanted_price(replyToken,message){ // 원하는 가격 입력받음 (0 이상만) |
129 | - if (message < 0){ | 157 | +// if (message < 0){ |
130 | - request.post( | 158 | +// request.post( |
131 | - { | 159 | +// { |
132 | - url: TARGET_URL, | 160 | +// url: TARGET_URL, |
133 | - headers: { | 161 | +// headers: { |
134 | - 'Authorization': `Bearer ${TOKEN}` | 162 | +// 'Authorization': `Bearer ${TOKEN}` |
135 | - }, | 163 | +// }, |
136 | - json: { | 164 | +// json: { |
137 | - "replyToken":eventObj.replyToken, | 165 | +// "replyToken":eventObj.replyToken, |
138 | - "messages":[ | 166 | +// "messages":[ |
139 | - { | 167 | +// { |
140 | - "type":"text", | 168 | +// "type":"text", |
141 | - "text":"Price must be positive number" | 169 | +// "text":"Price must be positive number" |
142 | - }, | 170 | +// }, |
143 | - ] | 171 | +// ] |
144 | - } | 172 | +// } |
145 | - },(error, response, body) => { | 173 | +// },(error, response, body) => { |
146 | - console.log(body) | 174 | +// console.log(body) |
147 | - }); | 175 | +// }); |
148 | - } | 176 | +// } |
149 | - | 177 | + |
150 | -} | 178 | +// } |
151 | 179 | ||
152 | function compare(s_code, wanted_price){ | 180 | function compare(s_code, wanted_price){ |
153 | const temp = axios.get(`https://finance.naver.com/item/main.nhn?code=${s_code}%22`).then( | 181 | const temp = axios.get(`https://finance.naver.com/item/main.nhn?code=${s_code}%22`).then( |
... | @@ -168,7 +196,7 @@ function compare(s_code, wanted_price){ | ... | @@ -168,7 +196,7 @@ function compare(s_code, wanted_price){ |
168 | 'Authorization': `Bearer ${TOKEN}` | 196 | 'Authorization': `Bearer ${TOKEN}` |
169 | }, | 197 | }, |
170 | json: { | 198 | json: { |
171 | - "replyToken":eventObj.replyToken, | 199 | + "replyToken":replyToken, |
172 | "messages":[ | 200 | "messages":[ |
173 | { | 201 | { |
174 | "type":"text", | 202 | "type":"text", | ... | ... |
-
Please register or login to post a comment