Toggle navigation
Toggle navigation
This project
Loading...
Sign in
장수창
/
COVID19_Information_Chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
장수창
2020-06-20 01:31:14 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7bff190fbcb4f83cf954d4a2ce378a689b31374a
7bff190f
1 parent
44b55f43
modified reply status
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
41 deletions
nodejs/app.js
nodejs/app.js
View file @
7bff190
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
axios
=
require
(
"axios"
);
const
cheerio
=
require
(
"cheerio"
);
const
url
=
"http://ncov.mohw.go.kr/"
;
// 질병관리본부 url
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
MULTI_TARGET_URL
=
'https://api.line.me/v2/bot/message/multicast'
const
BROAD_TARGET_URL
=
'https://api.line.me/v2/bot/message/broadcast'
const
TOKEN
=
'
yHHIa8B3iw072bvTv0u4RtmEEN1wrNi7onqWpKqoU/ceH4foYgIo6iHJbuZuepE72sMymCx7U761J1M/8So3gCWWRR34zvPp9YZpUFn07/hLSflcK6obioMeD6o108II/pvqfc/rZ+042re0ayIxIgdB04t89/1O/w1cDnyilFU=
'
const
TOKEN
=
''
const
NAVER_NEWS_ID
=
''
const
NAVER_NEWS_SECRET
=
''
const
fs
=
require
(
'fs'
);
...
...
@@ -57,47 +60,59 @@ app.post('/hook', function (req, res) {
//reply
function
replyNationWide
(
eventObj
)
{
//read status
var
strings
=
[
'날짜'
,
'확진환자'
,
'격리해제'
,
'검사진행'
,
'사망자'
]
var
fs
=
require
(
'fs'
);
var
array
=
fs
.
readFileSync
(
'status.txt'
).
toString
().
split
(
"\n"
);
for
(
i
in
array
)
{
strings
[
i
]
=
array
[
i
]
}
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
strings
[
0
]
},
{
"type"
:
"text"
,
"text"
:
strings
[
1
]
},
{
"type"
:
"text"
,
"text"
:
strings
[
2
]
},
{
"type"
:
"text"
,
"text"
:
strings
[
3
]
},
{
"type"
:
"text"
,
"text"
:
strings
[
4
]
},
]
request
.
post
(
url
,
function
(
err
,
res
,
body
)
{
const
$
=
cheerio
.
load
(
body
)
let
parentTag
=
$
(
"div.liveNum ul.liveNum li"
);
let
resultArr
=
[];
parentTag
.
each
(
function
(
i
,
elem
){
let
itemObj
=
{
text
:
$
(
this
).
find
(
"strong"
).
text
(),
num
:
$
(
this
).
find
(
"span"
).
text
()
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
resultArr
.
push
(
itemObj
);
})
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
resultArr
[
0
].
text
+
' : '
+
resultArr
[
0
].
num
.
replace
(
'(누적)'
,
''
).
replace
(
'(누적)'
,
''
).
replace
(
'전일대비'
,
''
)
},
{
"type"
:
"text"
,
"text"
:
resultArr
[
1
].
text
.
replace
(
'(격리해제)'
,
''
)
+
' : '
+
resultArr
[
1
].
num
.
replace
(
'(격리해제)'
,
''
)
},
{
"type"
:
"text"
,
"text"
:
resultArr
[
2
].
text
.
replace
(
'(격리 중)'
,
''
)
+
' : '
+
resultArr
[
2
].
num
.
replace
(
'(격리 중)'
,
''
)
},
{
"type"
:
"text"
,
"text"
:
resultArr
[
3
].
text
+
' : '
+
resultArr
[
3
].
num
},
{
"type"
:
"sticker"
,
"packageId"
:
"11539"
,
"stickerId"
:
"52114122"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
})
}
//hello
...
...
Please
register
or
login
to post a comment