박하늘

All functions update

...@@ -12,6 +12,9 @@ const bodyParser = require('body-parser'); ...@@ -12,6 +12,9 @@ const bodyParser = require('body-parser');
12 var app = express(); 12 var app = express();
13 13
14 14
15 +var holder1 = '';
16 +var holder2 = '';
17 +
15 18
16 19
17 app.use(bodyParser.json()); 20 app.use(bodyParser.json());
...@@ -25,20 +28,39 @@ app.post('/hook', function (req, res) { ...@@ -25,20 +28,39 @@ app.post('/hook', function (req, res) {
25 console.log('[request]', req.body); 28 console.log('[request]', req.body);
26 console.log('[request source] ', eventObj.source); 29 console.log('[request source] ', eventObj.source);
27 console.log('[request message]', eventObj.message); 30 console.log('[request message]', eventObj.message);
28 - 31 + if(eventObj.type == 'postback')
32 + {
33 + if(eventObj.postback.data == 'action=datetemp&selectId=1')
34 + {
35 + console.log("optimizer 실행")
36 + app.use('/simages', express.static(__dirname + '/src'));
37 + optimizer(eventObj.replyToken, holder1, holder2, eventObj.postback.params.date)
38 + app.use('/simages', express.static(__dirname + '/src'));
39 + }
40 + }
41 + else
42 + {
43 + if(eventObj.message.text.indexOf(' ') != -1)
44 + {
45 + date(eventObj.replyToken, eventObj.message.text)
46 + }
47 + else
48 + {
29 basicinform(eventObj.replyToken, eventObj.message.text) 49 basicinform(eventObj.replyToken, eventObj.message.text)
50 + }
51 +
52 + }
53 +
30 54
31 res.sendStatus(200); 55 res.sendStatus(200);
32 56
33 }); 57 });
34 58
35 function basicinform(replyToken, message) { 59 function basicinform(replyToken, message) {
36 -
37 var pystring; 60 var pystring;
38 const spawn = require("child_process").spawn; 61 const spawn = require("child_process").spawn;
39 const process = spawn("python", ["basic.py", message]); 62 const process = spawn("python", ["basic.py", message]);
40 const Callback = (data) => { 63 const Callback = (data) => {
41 - console.log("Data :", data.toString());
42 pystring = data.toString(); 64 pystring = data.toString();
43 if(pystring[0] == '1') 65 if(pystring[0] == '1')
44 { 66 {
...@@ -113,11 +135,133 @@ function basicinform(replyToken, message) { ...@@ -113,11 +135,133 @@ function basicinform(replyToken, message) {
113 console.log(body) 135 console.log(body)
114 }); 136 });
115 } 137 }
138 + };
139 + process.stdout.on("data", Callback);
140 +}
116 141
142 +function optimizer(replyToken, stock1, stock2, sdate) {
143 + sdate = sdate.toString();
144 + console.log(typeof(stock1), typeof(stock2), typeof(sdate))
145 + console.log(stock1, stock2, sdate)
146 + const spawn = require("child_process").spawn;
147 + const process = spawn("python", ["optimizer.py", stock1, stock2, sdate]);
148 + const Callback = (data) => {
149 + console.log(stock1, stock2, sdate)
150 + request.post(
151 + {
152 + url: TARGET_URL,
153 + headers: {
154 + 'Authorization': `Bearer ${TOKEN}`
155 + },
156 + json: {
157 + "replyToken":replyToken,
158 + "messages":[
159 + {
160 + "type":"text",
161 + "text":'조회하신 ' + holder1 +', ' + holder2 + '의 백테스트 결과입니다.'
162 + },
163 + {
164 + "type":"image",
165 + "originalContentUrl": "https://2017103989.oss2021.tk:23023/simages/test.png",
166 + "previewImageUrl": "https://2017103989.oss2021.tk:23023/simages/test.png"
167 + }
168 + ]
169 + }
170 + },(error, response, body) => {
171 + console.log(body)
172 + });
173 + }
174 + process.stdout.on("data", Callback);
175 +}
117 176
177 +function date(replyToken, message) {
178 + var holder = message.split(' ')
179 + holder1 = holder[0]
180 + holder2 = holder[1]
181 + var today = new Date();
182 + var year = today.getFullYear();
183 + var month = today.getMonth() + 1;
184 + var date = today.getDate();
185 + if(month < 10)
186 + {
187 + month = '0'+ month
188 + }
189 + if(date < 10)
190 + {
191 + date = '0'+ date
192 + }
193 + var stoday = year + '-' + month + '-' + date;
118 194
195 +
196 + const messageObject = {
197 + "type": "template",
198 + "altText": "this is a buttons template",
199 + "template": {
200 + "type": "buttons",
201 + "title": "조회하실 날짜를 선택하세요.",
202 + "text": "선택하신 날짜에서 현재(오늘)까지 조회됩니다.",
203 + "actions": [
204 + {
205 + "type": "datetimepicker",
206 + "label": "날짜 선택",
207 + "mode": "date",
208 + "initial":"2020-01-01",
209 + "max":stoday,
210 + "min":"2010-01-01",
211 + "data": "action=datetemp&selectId=1"
212 + },
213 + {
214 + "type": "postback",
215 + "label": "처음부터 다시할래요",
216 + "data": "action=cancel&selectId=2"
217 + },
218 + ]
219 + }
119 }; 220 };
120 - process.stdout.on("data", Callback); 221 + request.post(
222 + {
223 + url: TARGET_URL,
224 + headers: {
225 + 'Authorization': `Bearer ${TOKEN}`
226 + },
227 + json: {
228 + "replyToken":replyToken,
229 + "messages":[
230 + // {
231 + // "type":"text",
232 + // "text":'조회하실 날짜를 선택하세요. 선택하신 날짜에서 현재까지 조회됩니다.',
233 + // "quickReply": {
234 + // "items": [
235 + // {
236 + // "type": "action",
237 + // "action": {
238 + // "type": "datetimepicker",
239 + // "label":"날짜 선택하기",
240 + // "data":"storeId=12345",
241 + // "mode":"date",
242 + // "initial":"2015-01-01",
243 + // "max":stoday,
244 + // "min":"2010-01-01"
245 + // }
246 + // }
247 + // ]
248 + // }
249 + // },
250 + // {
251 + // "type":"text",
252 + // "text":req.body.postback.params
253 + // }
254 + messageObject
255 + ]
256 +
257 +
258 + }
259 + },(error, response, body) => {
260 + console.log(body)
261 + });
262 +
263 +
264 +
121 } 265 }
122 266
123 try { 267 try {
......
...@@ -10,7 +10,8 @@ def get_matches(query, choices, limit=3): ...@@ -10,7 +10,8 @@ def get_matches(query, choices, limit=3):
10 10
11 11
12 def basicinform(input): 12 def basicinform(input):
13 - stocks = pd.read_csv('stockcodename.csv', names=['Symbol', 'Market', 'Name', 'Sector', 'Industry', 'ListingDate', 'SettleMonth', 'Represetitive', 'HomePage', 'Region'], index_col=0) 13 + stocks = pd.read_csv('stockcodename.csv', names=['Symbol', 'Market', 'Name'
14 + , 'Sector', 'Industry', 'ListingDate', 'SettleMonth', 'Represetitive', 'HomePage', 'Region'], index_col=0)
14 symbol = '' 15 symbol = ''
15 16
16 for i in enumerate(stocks.Name): 17 for i in enumerate(stocks.Name):
...@@ -23,8 +24,8 @@ def basicinform(input): ...@@ -23,8 +24,8 @@ def basicinform(input):
23 cand = '' 24 cand = ''
24 for i in fuzzy: 25 for i in fuzzy:
25 cand += i[0] 26 cand += i[0]
26 - cand += " " 27 + cand += "\n"
27 - cand += "중 찾는게 있으신가요? \n다시 입력해주세요." 28 + cand += "중 찾는게 있으신가요? 다시 입력해주세요."
28 return cand 29 return cand
29 30
30 df = fdr.DataReader(symbol) 31 df = fdr.DataReader(symbol)
...@@ -33,15 +34,19 @@ def basicinform(input): ...@@ -33,15 +34,19 @@ def basicinform(input):
33 price = df.Close.iloc[-1] 34 price = df.Close.iloc[-1]
34 ror = ror_df[-1] 35 ror = ror_df[-1]
35 36
36 - value = { 37 + ror = round(ror, 4)
37 - "현재가": price, 38 + ror = ror * 100
38 - "거래랑": volume, 39 + value = ''
39 - "전일 대비 수익률:": ror 40 + value = "1현재가: " + str(price) + "원\n거래랑: " + str(volume) + "건\n전일대비: " + str(ror) + "%"
40 - } 41 + # value = {
42 + # "현재가": price,
43 + # "거래랑": volume,
44 + # "전일 대비 수익률:": ror
45 + # }
41 return value 46 return value
42 47
43 48
44 -# print(basicinform('신라호텔')) 49 +# print(basicinform('호텔신라'))
45 50
46 args = sys.argv 51 args = sys.argv
47 print(basicinform(args[1])) 52 print(basicinform(args[1]))
......
This diff is collapsed. Click to expand it.