Toggle navigation
Toggle navigation
This project
Loading...
Sign in
이진영
/
stockAlarm
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
Ubuntu
2021-06-08 15:06:23 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
919846e2ff2ebb6c470e8d9999e1d99327698784
919846e2
1 parent
3f132646
Adjust function
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
28 deletions
app.js
app.js
View file @
919846e
...
...
@@ -31,7 +31,7 @@ app.post('/hook', function (req, res) {
return
}
var
tempstockList
=
data
.
toString
().
split
(
"\n"
);
// ex) stockList = [[012312 ~~],[123012 ~~],[192312 ~~],[192310 ~~],[...]]
for
(
x
in
tempstockList
){
for
(
i
in
tempstockList
){
var
stockList
=
tempstockList
[
i
].
toString
().
split
(
" "
);
// ex) stockList = [[012312,~~],[1230012,~~],[1923,~~],[192310,~~],[...]]
}
// for (i in stockList) {
...
...
@@ -46,10 +46,11 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request message]'
,
eventObj
.
message
);
var
s_code
=
get_stock_code
(
stockList
,
stock_code
,
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
var
wanted_price
=
get_wanted_price
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
//
var wanted_price = get_wanted_price(eventObj.replyToken,eventObj.message.text);
cron
.
schedule
(
'*/5 * * * *'
,
()
=>
{
compare
(
s_code
,
wanted_price
);
console
.
log
(
'It works'
)
});
...
...
@@ -96,8 +97,35 @@ app.post('/hook', function (req, res) {
});
function
get_stock_code
(
stockList
,
stock_code
,
replyToken
,
message
){
var
temp
=
message
.
toString
().
split
(
" "
);
var
wanted_stock_name
=
temp
[
0
];
var
wanted_stock_price
=
temp
[
1
];
if
(
wanted_stock_price
<
0
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"Price must be positive number"
},
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
for
(
let
i
=
0
;
i
<
stockList
.
length
;
i
++
)
{
if
(
eventObj
.
message
.
text
==
stockList
[
i
][
1
]){
// 입력한거 나오면 코드로 바꿔줌
if
(
wanted_stock_name
==
stockList
[
i
][
1
]){
// 입력한거 나오면 코드로 바꿔줌
stock_code
=
stockList
[
i
][
0
]
return
stock_code
}
...
...
@@ -109,7 +137,7 @@ function get_stock_code(stockList,stock_code,replyToken,message){
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
...
...
@@ -125,29 +153,29 @@ function get_stock_code(stockList,stock_code,replyToken,message){
}
}
function
get_wanted_price
(
replyToken
,
message
){
if
(
message
<
0
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"Price must be positive number"
},
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
}
// function get_wanted_price(replyToken,message){ // 원하는 가격 입력받음 (0 이상만)
//
if (message < 0){
//
request.post(
//
{
//
url: TARGET_URL,
//
headers: {
//
'Authorization': `Bearer ${TOKEN}`
//
},
//
json: {
//
"replyToken":eventObj.replyToken,
//
"messages":[
//
{
//
"type":"text",
//
"text":"Price must be positive number"
//
},
//
]
//
}
//
},(error, response, body) => {
//
console.log(body)
//
});
//
}
//
}
function
compare
(
s_code
,
wanted_price
){
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){
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
...
...
Please
register
or
login
to post a comment