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 12:41:30 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a29dfb6b6a5ea78564d15a42fb0bef6b17572553
a29dfb6b
1 parent
08f335c3
Add necessary functions
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
120 additions
and
47 deletions
app.js
package.json
app.js
View file @
a29dfb6
...
...
@@ -12,9 +12,6 @@ const axios = require('axios')
const
cheerio
=
require
(
'cheerio'
)
var
app
=
express
();
var
cron
=
require
(
'node-cron'
);
const
fs
=
require
(
'fs'
);
var
app
=
express
();
var
stock_code
=
"005930"
app
.
use
(
bodyParser
.
json
());
...
...
@@ -26,7 +23,7 @@ app.post('/hook', function (req, res) {
let
stockList
=
[];
import
'./stock_names.txt'
;
//
import './stock_names.txt';
fs
.
readFile
(
'./stock_names.txt'
,
'utf8'
,
(
err
,
data
)
=>
{
// 파일 import하고 stockList로 저장
if
(
err
){
...
...
@@ -48,31 +45,14 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
<<<<<<<
HEAD
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
);
cron
.
schedule
(
'*/5 * * * *'
,
()
=>
{
const
temp
=
axios
.
get
(
`https://finance.naver.com/item/main.nhn?code=
${
stock_code
}
%22`
).
then
(
res
=>
{
let
urList
=
[];
const
$
=
cheerio
.
load
(
res
.
data
)
const
$bodyList
=
$
(
"dl.blind"
).
children
(
"dd"
).
text
();
const
result
=
$bodyList
.
slice
(
73
,
80
)
// 실시간으로 변하는 주식 가격 scrape
console
.
log
(
result
)
}
)
compare
(
s_code
,
wanted_price
);
});
=======
for
(
let
i
=
0
;
i
<
stockList
.
length
;
i
++
)
{
if
(
eventObj
.
message
.
text
==
stockList
[
i
][
1
]){
// 입력한거 나오면 코드로 바꿔줌
stock_code
=
stockList
[
i
][
0
]
}
else
{
console
.
log
(
'Not in list'
);
}
}
// if (eventObj.message.text == "영어"){
// lan = "en"
...
...
@@ -86,33 +66,125 @@ app.post('/hook', function (req, res) {
// else{
// trans(eventObj.replyToken, eventObj.message.text);
// }
>>>>>>>
stock_list
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"Hello, user"
// request.post(
// {
// url: TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "replyToken":eventObj.replyToken,
// "messages":[
// {
// "type":"text",
// "text":"Hello, user"
// },
// {
// "type":"text",
// "text":"May I help you?"
// }
// ]
// }
// },(error, response, body) => {
// console.log(body)
// });
res
.
sendStatus
(
200
);
});
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에 없으면 없다고 보냄
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
{
"type"
:
"text"
,
"text"
:
"May I help you?"
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"Not in list"
},
]
}
]
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
}
}
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
compare
(
s_code
,
wanted_price
){
const
temp
=
axios
.
get
(
`https://finance.naver.com/item/main.nhn?code=
${
s_code
}
%22`
).
then
(
res
=>
{
let
urList
=
[];
const
$
=
cheerio
.
load
(
res
.
data
)
const
$bodyList
=
$
(
"dl.blind"
).
children
(
"dd"
).
text
();
const
result
=
$bodyList
.
slice
(
73
,
80
)
// 실시간으로 변하는 주식 가격 scrape
console
.
log
(
result
)
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
)
if
(
int
(
result
)
<=
wanted_price
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"Reached wanted price!"
},
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
res
.
sendStatus
(
200
);
});
}
try
{
...
...
package.json
View file @
a29dfb6
...
...
@@ -12,7 +12,8 @@
},
"devDependencies"
:
{},
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
,
"start"
:
"node app.js"
},
"repository"
:
{
"type"
:
"git"
,
...
...
Please
register
or
login
to post a comment