Showing
1 changed file
with
50 additions
and
51 deletions
... | @@ -2,11 +2,12 @@ var express = require('express'); | ... | @@ -2,11 +2,12 @@ var express = require('express'); |
2 | const request = require('request'); | 2 | const request = require('request'); |
3 | const axios = require("axios"); | 3 | const axios = require("axios"); |
4 | const cheerio = require("cheerio"); | 4 | const cheerio = require("cheerio"); |
5 | -const url = "http://ncov.mohw.go.kr/"; // 질병관리본부 url | 5 | +const ncov_url = "http://ncov.mohw.go.kr/"; // 질병관리본부 url |
6 | +const yongin_url = 'http://www.yongin.go.kr/health/ictsd/INC_selectIctsdPatntList.do?q_currPage=1&q_rowPerPage=10&_=1592578382959'; // 용인시 | ||
6 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 7 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
7 | const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' | 8 | const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' |
8 | const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' | 9 | const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' |
9 | -const TOKEN = '' | 10 | +const TOKEN = '///////' |
10 | const NAVER_NEWS_ID = '' | 11 | const NAVER_NEWS_ID = '' |
11 | const NAVER_NEWS_SECRET = '' | 12 | const NAVER_NEWS_SECRET = '' |
12 | const fs = require('fs'); | 13 | const fs = require('fs'); |
... | @@ -14,10 +15,10 @@ const path = require('path'); | ... | @@ -14,10 +15,10 @@ const path = require('path'); |
14 | const HTTPS = require('https'); | 15 | const HTTPS = require('https'); |
15 | const domain = "www.osschatbot2020.tk" | 16 | const domain = "www.osschatbot2020.tk" |
16 | const sslport = 23023; | 17 | const sslport = 23023; |
17 | - | ||
18 | const bodyParser = require('body-parser'); | 18 | const bodyParser = require('body-parser'); |
19 | var app = express(); | 19 | var app = express(); |
20 | 20 | ||
21 | + | ||
21 | // broadcast route | 22 | // broadcast route |
22 | var period_broadcast = 50000; | 23 | var period_broadcast = 50000; |
23 | var count_broadcast = 0; | 24 | var count_broadcast = 0; |
... | @@ -57,10 +58,10 @@ app.post('/hook', function (req, res) { | ... | @@ -57,10 +58,10 @@ app.post('/hook', function (req, res) { |
57 | res.sendStatus(200); | 58 | res.sendStatus(200); |
58 | }); | 59 | }); |
59 | 60 | ||
60 | -//reply | 61 | +// reply |
61 | function replyNationWide(eventObj) { | 62 | function replyNationWide(eventObj) { |
62 | //read status | 63 | //read status |
63 | - request.post(url, function (err, res, body) { | 64 | + request.post(ncov_url, function (err, res, body) { |
64 | 65 | ||
65 | const $ = cheerio.load(body) | 66 | const $ = cheerio.load(body) |
66 | let parentTag = $("div.liveNum ul.liveNum li"); | 67 | let parentTag = $("div.liveNum ul.liveNum li"); |
... | @@ -115,7 +116,7 @@ function replyNationWide(eventObj) { | ... | @@ -115,7 +116,7 @@ function replyNationWide(eventObj) { |
115 | 116 | ||
116 | } | 117 | } |
117 | 118 | ||
118 | -//hello | 119 | +// hello |
119 | function hello(eventObj) { | 120 | function hello(eventObj) { |
120 | 121 | ||
121 | request.post( | 122 | request.post( |
... | @@ -140,6 +141,10 @@ function hello(eventObj) { | ... | @@ -140,6 +141,10 @@ function hello(eventObj) { |
140 | "text":"코로나 19 관련 뉴스는 '뉴스'를 타이핑 해주세요." | 141 | "text":"코로나 19 관련 뉴스는 '뉴스'를 타이핑 해주세요." |
141 | }, | 142 | }, |
142 | { | 143 | { |
144 | + "type":"text", | ||
145 | + "text":"감사합니다." | ||
146 | + }, | ||
147 | + { | ||
143 | "type": "sticker", | 148 | "type": "sticker", |
144 | "packageId": "11539", | 149 | "packageId": "11539", |
145 | "stickerId": "52114110" | 150 | "stickerId": "52114110" |
... | @@ -152,55 +157,49 @@ function hello(eventObj) { | ... | @@ -152,55 +157,49 @@ function hello(eventObj) { |
152 | }); | 157 | }); |
153 | } | 158 | } |
154 | 159 | ||
155 | -// Broadcast | 160 | +// Broadcast yongin |
156 | function broadcast(){ | 161 | function broadcast(){ |
162 | + | ||
163 | + request.post(yongin_url, function (err, res, body) { | ||
157 | 164 | ||
158 | - request.post( | 165 | + const $ = cheerio.load(body) |
159 | - { | 166 | + let parentTag = $("div.view_content"); |
160 | - url: BROAD_TARGET_URL, | 167 | + |
161 | - headers: { | 168 | + let resultArr = []; |
162 | - 'Authorization': `Bearer ${TOKEN}` | 169 | + parentTag.each(function (i, elem) { |
163 | - }, | 170 | + let itemObj = { |
164 | - json: { | 171 | + text: $(this).find("p").text(), |
165 | - "messages":[ | ||
166 | - { | ||
167 | - "type":"text", | ||
168 | - "text":"Hello, user" | ||
169 | - }, | ||
170 | - { | ||
171 | - "type":"text", | ||
172 | - "text":"May I help you?" | ||
173 | - } | ||
174 | - ] | ||
175 | } | 172 | } |
176 | - },(error, response, body) => { | 173 | + resultArr.push(itemObj); |
177 | - console.log(body) | 174 | + }) |
178 | - }); | 175 | + var fs = require('fs'); |
179 | -} | 176 | + var array = fs.readFileSync('yongin.txt').toString().split("\n"); |
177 | + | ||
178 | + request.post( | ||
179 | + { | ||
180 | + url: BROAD_TARGET_URL, | ||
181 | + headers: { | ||
182 | + 'Authorization': `Bearer ${TOKEN}` | ||
183 | + }, | ||
184 | + json: { | ||
185 | + "messages":[ | ||
186 | + { | ||
187 | + "type":"text", | ||
188 | + "text":"용인시 확진자의 동선이 공개되었습니다." | ||
189 | + }, | ||
190 | + { | ||
191 | + "type": "sticker", | ||
192 | + "packageId": "11539", | ||
193 | + "stickerId": "52114110" | ||
194 | + } | ||
195 | + ] | ||
196 | + } | ||
197 | + },(error, response, body) => { | ||
198 | + console.log(body) | ||
199 | + }); | ||
180 | 200 | ||
181 | -// Multicast User | 201 | + }) |
182 | -// request.post( | 202 | +} |
183 | -// { | ||
184 | -// url: MULTI_TARGET_URL, | ||
185 | -// headers: { | ||
186 | -// 'Authorization': `Bearer ${TOKEN}` | ||
187 | -// }, | ||
188 | -// json: { | ||
189 | -// "to": [`${USER_ID}`], | ||
190 | -// "messages":[ | ||
191 | -// { | ||
192 | -// "type":"text", | ||
193 | -// "text":"용인시" | ||
194 | -// }, | ||
195 | -// { | ||
196 | -// "type":"text", | ||
197 | -// "text":"용인시" | ||
198 | -// } | ||
199 | -// ] | ||
200 | -// } | ||
201 | -// },(error, response, body) => { | ||
202 | -// console.log(body) | ||
203 | -// }); | ||
204 | 203 | ||
205 | //reply news | 204 | //reply news |
206 | function replyNews(eventObj) { | 205 | function replyNews(eventObj) { | ... | ... |
-
Please register or login to post a comment