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