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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
17 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,12 +97,11 @@ app.post('/hook', function (req, res) {
});
function
get_stock_code
(
stockList
,
stock_code
,
replyToken
,
message
){
for
(
let
i
=
0
;
i
<
stockList
.
length
;
i
++
)
{
if
(
eventObj
.
message
.
text
==
stockList
[
i
][
1
]){
// 입력한거 나오면 코드로 바꿔줌
stock_code
=
stockList
[
i
][
0
]
return
stock_code
}
else
{
// stockList에 없으면 없다고 보냄
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
,
...
...
@@ -109,24 +109,27 @@ function get_stock_code(stockList,stock_code,replyToken,message){
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"Not in list
"
"text"
:
"Price must be positive number
"
},
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
}
}
function
get_wanted_price
(
replyToken
,
message
){
if
(
message
<
0
){
for
(
let
i
=
0
;
i
<
stockList
.
length
;
i
++
)
{
if
(
wanted_stock_name
==
stockList
[
i
][
1
]){
// 입력한거 나오면 코드로 바꿔줌
stock_code
=
stockList
[
i
][
0
]
return
stock_code
}
else
{
// stockList에 없으면 없다고 보냄
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -134,11 +137,11 @@ function get_wanted_price(replyToken,message){
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"Price must be positive number
"
"text"
:
"Not in list
"
},
]
}
...
...
@@ -147,8 +150,33 @@ function get_wanted_price(replyToken,message){
});
}
}
}
// 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
(
res
=>
{
...
...
@@ -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