Showing
2 changed files
with
94 additions
and
30 deletions
1 | -//app.js | ||
2 | - | ||
3 | var express = require('express'); | 1 | var express = require('express'); |
2 | +const request = require('request'); | ||
3 | +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
4 | +const TOKEN = 'OVIxKODBqM8Pn2dpFtFeSLsDbBvApfTu88rh8wFGOzfvgvPjmBH0A4XKii97VxIDO9shYyTix4qGq32vwvL895Rbss5VSVEiU/XG5lOdyTLgECkSQKOdObSetZwcVHbGmzZJ+0Cz5vZrB5KuImOwrwdB04t89/1O/w1cDnyilFU=' | ||
5 | +const fs = require('fs'); | ||
6 | +const path = require('path'); | ||
7 | +const HTTPS = require('https'); | ||
8 | +const domain = "2017103989.oss2021.tk" | ||
9 | +const sslport = 23023; | ||
10 | + | ||
11 | +const bodyParser = require('body-parser'); | ||
4 | var app = express(); | 12 | var app = express(); |
13 | +app.use(bodyParser.json()); | ||
14 | +app.post('/hook', function (req, res) { | ||
15 | + | ||
16 | + var eventObj = req.body.events[0]; | ||
17 | + var source = eventObj.source; | ||
18 | + var message = eventObj.message; | ||
19 | + | ||
20 | + | ||
21 | + var spawn = require('child_process').spawn; | ||
22 | + var process = spawn('pyhton3', ["./basic.py", eventObj.message.text]); | ||
23 | + process.stdout.on('data', function(data){ | ||
24 | + console.log(data.toString()); | ||
25 | + }) | ||
26 | + | ||
5 | 27 | ||
6 | -app.use(express.urlencoded({ extended: false })); | 28 | + // request log |
7 | -app.use(express.json()); | 29 | + console.log('======================', new Date() ,'======================'); |
30 | + console.log('[request]', req.body); | ||
31 | + console.log('[request source] ', eventObj.source); | ||
32 | + console.log('[request message]', eventObj.message); | ||
8 | 33 | ||
9 | -app.get('/keyboard', (req, res) => { | 34 | + request.post( |
10 | - var data = {'type': 'text'} | 35 | + { |
11 | - res.json(data); | 36 | + url: TARGET_URL, |
37 | + headers: { | ||
38 | + 'Authorization': `Bearer ${TOKEN}` | ||
39 | + }, | ||
40 | + json: { | ||
41 | + "replyToken":eventObj.replyToken, | ||
42 | + "messages":[ | ||
43 | + { | ||
44 | + "type":"text", | ||
45 | + "text":"Hello" | ||
46 | + }, | ||
47 | + { | ||
48 | + "type":"text", | ||
49 | + "text":"May I help you?" | ||
50 | + } | ||
51 | + ] | ||
52 | + } | ||
53 | + },(error, response, body) => { | ||
54 | + console.log(body) | ||
55 | + }); | ||
56 | + | ||
57 | + | ||
58 | + res.sendStatus(200); | ||
12 | }); | 59 | }); |
13 | 60 | ||
14 | -app.post('/message', (req, res) => { | 61 | +try { |
15 | - var question = req.body.userRequest.utterance; | 62 | + const option = { |
16 | - var goMain = '처음으로'; | 63 | + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), |
64 | + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), | ||
65 | + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | ||
66 | + }; | ||
17 | 67 | ||
18 | - if (question === '테스트') { | 68 | + HTTPS.createServer(option, app).listen(sslport, () => { |
19 | - var data = { | 69 | + console.log(`[HTTPS] Server is started on port ${sslport}`); |
20 | - 'version': '2.0', | 70 | + }); |
21 | - 'template': { | 71 | + } catch (error) { |
22 | - 'outputs': [{ | 72 | + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); |
23 | - 'simpleText': { | 73 | + console.log(error); |
24 | - 'text': '테스트' | ||
25 | - } | ||
26 | - }], | ||
27 | - 'quickReplies': [{ | ||
28 | - 'label': goMain, | ||
29 | - 'action': 'message', | ||
30 | - 'messageText': goMain | ||
31 | - }] | ||
32 | - } | ||
33 | - } | ||
34 | } | 74 | } |
35 | - res.json(data); | ||
36 | -}); | ||
37 | - | ||
38 | -app.listen(3000, () => console.log('node on 3000')); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
75 | + | ... | ... |
server/basic.py
0 → 100644
1 | +import FinanceDataReader as fdr | ||
2 | +import pandas as pd | ||
3 | +import sys | ||
4 | + | ||
5 | +def basicinform(input): | ||
6 | + stocks = pd.read_csv('stockcodename.csv', index_col=0) | ||
7 | + symbol = '' | ||
8 | + for i in enumerate(stocks.Name): | ||
9 | + if i[1] == input: | ||
10 | + symbol = (stocks.iloc[i[0]].Symbol) | ||
11 | + break | ||
12 | + | ||
13 | + df = fdr.DataReader(symbol) | ||
14 | + ror_df = df.Close.pct_change() | ||
15 | + volume = df.Volume.iloc[-1] | ||
16 | + price = df.Close.iloc[-1] | ||
17 | + ror = ror_df[-1] | ||
18 | + | ||
19 | + value = { | ||
20 | + "현재가": price, | ||
21 | + "거래랑": volume, | ||
22 | + "전일 대비 수익률:": ror | ||
23 | + } | ||
24 | + return value | ||
25 | + | ||
26 | +args = sys.argv | ||
27 | +print(basicinform(sys.args[1])) |
-
Please register or login to post a comment