Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박하늘
/
stock_chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박하늘
2021-06-07 04:21:24 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
86f5faa58e98ac529da4a9d9c5a5425805393a8a
86f5faa5
1 parent
6364226b
All functions update
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
164 additions
and
15 deletions
server/app.js
server/basic.py
server/optimizer.py
server/app.js
View file @
86f5faa
...
...
@@ -12,6 +12,9 @@ const bodyParser = require('body-parser');
var
app
=
express
();
var
holder1
=
''
;
var
holder2
=
''
;
app
.
use
(
bodyParser
.
json
());
...
...
@@ -25,20 +28,39 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
if
(
eventObj
.
type
==
'postback'
)
{
if
(
eventObj
.
postback
.
data
==
'action=datetemp&selectId=1'
)
{
console
.
log
(
"optimizer 실행"
)
app
.
use
(
'/simages'
,
express
.
static
(
__dirname
+
'/src'
));
optimizer
(
eventObj
.
replyToken
,
holder1
,
holder2
,
eventObj
.
postback
.
params
.
date
)
app
.
use
(
'/simages'
,
express
.
static
(
__dirname
+
'/src'
));
}
}
else
{
if
(
eventObj
.
message
.
text
.
indexOf
(
' '
)
!=
-
1
)
{
date
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
}
else
{
basicinform
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
}
basicinform
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
}
res
.
sendStatus
(
200
);
});
function
basicinform
(
replyToken
,
message
)
{
var
pystring
;
const
spawn
=
require
(
"child_process"
).
spawn
;
const
process
=
spawn
(
"python"
,
[
"basic.py"
,
message
]);
const
Callback
=
(
data
)
=>
{
console
.
log
(
"Data :"
,
data
.
toString
());
pystring
=
data
.
toString
();
if
(
pystring
[
0
]
==
'1'
)
{
...
...
@@ -113,11 +135,133 @@ function basicinform(replyToken, message) {
console
.
log
(
body
)
});
}
};
process
.
stdout
.
on
(
"data"
,
Callback
);
}
function
optimizer
(
replyToken
,
stock1
,
stock2
,
sdate
)
{
sdate
=
sdate
.
toString
();
console
.
log
(
typeof
(
stock1
),
typeof
(
stock2
),
typeof
(
sdate
))
console
.
log
(
stock1
,
stock2
,
sdate
)
const
spawn
=
require
(
"child_process"
).
spawn
;
const
process
=
spawn
(
"python"
,
[
"optimizer.py"
,
stock1
,
stock2
,
sdate
]);
const
Callback
=
(
data
)
=>
{
console
.
log
(
stock1
,
stock2
,
sdate
)
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
'조회하신 '
+
holder1
+
', '
+
holder2
+
'의 백테스트 결과입니다.'
},
{
"type"
:
"image"
,
"originalContentUrl"
:
"https://2017103989.oss2021.tk:23023/simages/test.png"
,
"previewImageUrl"
:
"https://2017103989.oss2021.tk:23023/simages/test.png"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
process
.
stdout
.
on
(
"data"
,
Callback
);
}
function
date
(
replyToken
,
message
)
{
var
holder
=
message
.
split
(
' '
)
holder1
=
holder
[
0
]
holder2
=
holder
[
1
]
var
today
=
new
Date
();
var
year
=
today
.
getFullYear
();
var
month
=
today
.
getMonth
()
+
1
;
var
date
=
today
.
getDate
();
if
(
month
<
10
)
{
month
=
'0'
+
month
}
if
(
date
<
10
)
{
date
=
'0'
+
date
}
var
stoday
=
year
+
'-'
+
month
+
'-'
+
date
;
const
messageObject
=
{
"type"
:
"template"
,
"altText"
:
"this is a buttons template"
,
"template"
:
{
"type"
:
"buttons"
,
"title"
:
"조회하실 날짜를 선택하세요."
,
"text"
:
"선택하신 날짜에서 현재(오늘)까지 조회됩니다."
,
"actions"
:
[
{
"type"
:
"datetimepicker"
,
"label"
:
"날짜 선택"
,
"mode"
:
"date"
,
"initial"
:
"2020-01-01"
,
"max"
:
stoday
,
"min"
:
"2010-01-01"
,
"data"
:
"action=datetemp&selectId=1"
},
{
"type"
:
"postback"
,
"label"
:
"처음부터 다시할래요"
,
"data"
:
"action=cancel&selectId=2"
},
]
}
};
process
.
stdout
.
on
(
"data"
,
Callback
);
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
// {
// "type":"text",
// "text":'조회하실 날짜를 선택하세요. 선택하신 날짜에서 현재까지 조회됩니다.',
// "quickReply": {
// "items": [
// {
// "type": "action",
// "action": {
// "type": "datetimepicker",
// "label":"날짜 선택하기",
// "data":"storeId=12345",
// "mode":"date",
// "initial":"2015-01-01",
// "max":stoday,
// "min":"2010-01-01"
// }
// }
// ]
// }
// },
// {
// "type":"text",
// "text":req.body.postback.params
// }
messageObject
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
try
{
...
...
@@ -134,4 +278,4 @@ try {
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
...
...
server/basic.py
View file @
86f5faa
...
...
@@ -10,7 +10,8 @@ def get_matches(query, choices, limit=3):
def
basicinform
(
input
):
stocks
=
pd
.
read_csv
(
'stockcodename.csv'
,
names
=
[
'Symbol'
,
'Market'
,
'Name'
,
'Sector'
,
'Industry'
,
'ListingDate'
,
'SettleMonth'
,
'Represetitive'
,
'HomePage'
,
'Region'
],
index_col
=
0
)
stocks
=
pd
.
read_csv
(
'stockcodename.csv'
,
names
=
[
'Symbol'
,
'Market'
,
'Name'
,
'Sector'
,
'Industry'
,
'ListingDate'
,
'SettleMonth'
,
'Represetitive'
,
'HomePage'
,
'Region'
],
index_col
=
0
)
symbol
=
''
for
i
in
enumerate
(
stocks
.
Name
):
...
...
@@ -23,8 +24,8 @@ def basicinform(input):
cand
=
''
for
i
in
fuzzy
:
cand
+=
i
[
0
]
cand
+=
"
"
cand
+=
"중 찾는게 있으신가요?
\n
다시 입력해주세요."
cand
+=
"
\n
"
cand
+=
"중 찾는게 있으신가요? 다시 입력해주세요."
return
cand
df
=
fdr
.
DataReader
(
symbol
)
...
...
@@ -33,15 +34,19 @@ def basicinform(input):
price
=
df
.
Close
.
iloc
[
-
1
]
ror
=
ror_df
[
-
1
]
value
=
{
"현재가"
:
price
,
"거래랑"
:
volume
,
"전일 대비 수익률:"
:
ror
}
ror
=
round
(
ror
,
4
)
ror
=
ror
*
100
value
=
''
value
=
"1현재가: "
+
str
(
price
)
+
"원
\n
거래랑: "
+
str
(
volume
)
+
"건
\n
전일대비: "
+
str
(
ror
)
+
"
%
"
# value = {
# "현재가": price,
# "거래랑": volume,
# "전일 대비 수익률:": ror
# }
return
value
# print(basicinform('
신라호텔
'))
# print(basicinform('
호텔신라
'))
args
=
sys
.
argv
print
(
basicinform
(
args
[
1
]))
...
...
server/optimizer.py
0 → 100644
View file @
86f5faa
This diff is collapsed. Click to expand it.
Please
register
or
login
to post a comment