Showing
1 changed file
with
56 additions
and
41 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | const request = require('request'); | 2 | const request = require('request'); |
3 | +const axios = require("axios"); | ||
4 | +const cheerio = require("cheerio"); | ||
5 | +const url = "http://ncov.mohw.go.kr/"; // 질병관리본부 url | ||
3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 6 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
4 | const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' | 7 | const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' |
5 | const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' | 8 | const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' |
6 | -const TOKEN = 'yHHIa8B3iw072bvTv0u4RtmEEN1wrNi7onqWpKqoU/ceH4foYgIo6iHJbuZuepE72sMymCx7U761J1M/8So3gCWWRR34zvPp9YZpUFn07/hLSflcK6obioMeD6o108II/pvqfc/rZ+042re0ayIxIgdB04t89/1O/w1cDnyilFU=' | 9 | +const TOKEN = '' |
7 | const NAVER_NEWS_ID = '' | 10 | const NAVER_NEWS_ID = '' |
8 | const NAVER_NEWS_SECRET = '' | 11 | const NAVER_NEWS_SECRET = '' |
9 | const fs = require('fs'); | 12 | const fs = require('fs'); |
... | @@ -57,47 +60,59 @@ app.post('/hook', function (req, res) { | ... | @@ -57,47 +60,59 @@ app.post('/hook', function (req, res) { |
57 | //reply | 60 | //reply |
58 | function replyNationWide(eventObj) { | 61 | function replyNationWide(eventObj) { |
59 | //read status | 62 | //read status |
60 | - var strings = ['날짜', '확진환자', '격리해제', '검사진행', '사망자'] | 63 | + request.post(url, function (err, res, body) { |
61 | - var fs = require('fs'); | 64 | + |
62 | - var array = fs.readFileSync('status.txt').toString().split("\n"); | 65 | + const $ = cheerio.load(body) |
63 | - for(i in array) { | 66 | + let parentTag = $("div.liveNum ul.liveNum li"); |
64 | - strings[i] = array[i] | 67 | + |
65 | - } | 68 | + let resultArr = []; |
66 | - | 69 | + parentTag.each(function(i, elem){ |
67 | - request.post( | 70 | + let itemObj = { |
68 | - { | 71 | + text : $(this).find("strong").text(), |
69 | - url: TARGET_URL, | 72 | + num :$(this).find("span").text() |
70 | - headers: { | ||
71 | - 'Authorization': `Bearer ${TOKEN}` | ||
72 | - }, | ||
73 | - json: { | ||
74 | - "replyToken":eventObj.replyToken, | ||
75 | - "messages":[ | ||
76 | - { | ||
77 | - "type":"text", | ||
78 | - "text":strings[0] | ||
79 | - }, | ||
80 | - { | ||
81 | - "type":"text", | ||
82 | - "text":strings[1] | ||
83 | - }, | ||
84 | - { | ||
85 | - "type":"text", | ||
86 | - "text":strings[2] | ||
87 | - }, | ||
88 | - { | ||
89 | - "type":"text", | ||
90 | - "text":strings[3] | ||
91 | - }, | ||
92 | - { | ||
93 | - "type":"text", | ||
94 | - "text":strings[4] | ||
95 | - }, | ||
96 | - ] | ||
97 | } | 73 | } |
98 | - },(error, response, body) => { | 74 | + resultArr.push(itemObj); |
99 | - console.log(body) | 75 | + }) |
100 | - }); | 76 | + |
77 | + request.post( | ||
78 | + { | ||
79 | + url: TARGET_URL, | ||
80 | + headers: { | ||
81 | + 'Authorization': `Bearer ${TOKEN}` | ||
82 | + }, | ||
83 | + json: { | ||
84 | + "replyToken":eventObj.replyToken, | ||
85 | + "messages":[ | ||
86 | + { | ||
87 | + "type":"text", | ||
88 | + "text":resultArr[0].text + ' : ' + resultArr[0].num.replace('(누적)', '').replace('(누적)', '').replace('전일대비', '') | ||
89 | + }, | ||
90 | + { | ||
91 | + "type":"text", | ||
92 | + "text":resultArr[1].text.replace('(격리해제)', '') + ' : ' + resultArr[1].num.replace('(격리해제)', '') | ||
93 | + }, | ||
94 | + { | ||
95 | + "type":"text", | ||
96 | + "text":resultArr[2].text.replace('(격리 중)', '') + ' : ' + resultArr[2].num.replace('(격리 중)', '') | ||
97 | + }, | ||
98 | + { | ||
99 | + "type":"text", | ||
100 | + "text":resultArr[3].text + ' : ' + resultArr[3].num | ||
101 | + }, | ||
102 | + { | ||
103 | + "type": "sticker", | ||
104 | + "packageId": "11539", | ||
105 | + "stickerId": "52114122" | ||
106 | + } | ||
107 | + ] | ||
108 | + } | ||
109 | + },(error, response, body) => { | ||
110 | + console.log(body) | ||
111 | + }); | ||
112 | + | ||
113 | + }) | ||
114 | + | ||
115 | + | ||
101 | } | 116 | } |
102 | 117 | ||
103 | //hello | 118 | //hello | ... | ... |
-
Please register or login to post a comment