Showing
1 changed file
with
28 additions
and
13 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,12 +60,19 @@ app.post('/hook', function (req, res) { | ... | @@ -57,12 +60,19 @@ 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 | + |
68 | + let resultArr = []; | ||
69 | + parentTag.each(function(i, elem){ | ||
70 | + let itemObj = { | ||
71 | + text : $(this).find("strong").text(), | ||
72 | + num :$(this).find("span").text() | ||
65 | } | 73 | } |
74 | + resultArr.push(itemObj); | ||
75 | + }) | ||
66 | 76 | ||
67 | request.post( | 77 | request.post( |
68 | { | 78 | { |
... | @@ -75,29 +85,34 @@ function replyNationWide(eventObj) { | ... | @@ -75,29 +85,34 @@ function replyNationWide(eventObj) { |
75 | "messages":[ | 85 | "messages":[ |
76 | { | 86 | { |
77 | "type":"text", | 87 | "type":"text", |
78 | - "text":strings[0] | 88 | + "text":resultArr[0].text + ' : ' + resultArr[0].num.replace('(누적)', '').replace('(누적)', '').replace('전일대비', '') |
79 | }, | 89 | }, |
80 | { | 90 | { |
81 | "type":"text", | 91 | "type":"text", |
82 | - "text":strings[1] | 92 | + "text":resultArr[1].text.replace('(격리해제)', '') + ' : ' + resultArr[1].num.replace('(격리해제)', '') |
83 | }, | 93 | }, |
84 | { | 94 | { |
85 | "type":"text", | 95 | "type":"text", |
86 | - "text":strings[2] | 96 | + "text":resultArr[2].text.replace('(격리 중)', '') + ' : ' + resultArr[2].num.replace('(격리 중)', '') |
87 | }, | 97 | }, |
88 | { | 98 | { |
89 | "type":"text", | 99 | "type":"text", |
90 | - "text":strings[3] | 100 | + "text":resultArr[3].text + ' : ' + resultArr[3].num |
91 | }, | 101 | }, |
92 | { | 102 | { |
93 | - "type":"text", | 103 | + "type": "sticker", |
94 | - "text":strings[4] | 104 | + "packageId": "11539", |
95 | - }, | 105 | + "stickerId": "52114122" |
106 | + } | ||
96 | ] | 107 | ] |
97 | } | 108 | } |
98 | },(error, response, body) => { | 109 | },(error, response, body) => { |
99 | console.log(body) | 110 | console.log(body) |
100 | }); | 111 | }); |
112 | + | ||
113 | + }) | ||
114 | + | ||
115 | + | ||
101 | } | 116 | } |
102 | 117 | ||
103 | //hello | 118 | //hello | ... | ... |
-
Please register or login to post a comment