From b6bbfb12c1a658da82a9397f3d88ac1e7082a459 Mon Sep 17 00:00:00 2001 From: ciaran <760218327@qq.com> Date: Mon, 25 Feb 2019 11:32:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=81=9C=E6=B0=B4=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=20(#1605)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复广州停水通知 - 添加西安停水通知路由 - 添加阳江停水通知路由 --- docs/README.md | 4 +++ lib/router.js | 2 ++ lib/routes/tingshuitz/guangzhou.js | 34 ++++++++++++------------- lib/routes/tingshuitz/xian.js | 31 +++++++++++++++++++++++ lib/routes/tingshuitz/yangjiang.js | 40 ++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 lib/routes/tingshuitz/xian.js create mode 100644 lib/routes/tingshuitz/yangjiang.js diff --git a/docs/README.md b/docs/README.md index e6096fad1..d53b964e3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2183,6 +2183,10 @@ category 对应的关键词有 + + + + ### 停电通知 获取未来一天的停电通知 diff --git a/lib/router.js b/lib/router.js index 45e92a49c..e2c0304f7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -373,6 +373,8 @@ router.get('/tingshuitz/xiaoshan', require('./routes/tingshuitz/xiaoshan')); router.get('/tingshuitz/dalian', require('./routes/tingshuitz/dalian')); router.get('/tingshuitz/guangzhou', require('./routes/tingshuitz/guangzhou')); router.get('/tingshuitz/dongguan', require('./routes/tingshuitz/dongguan')); +router.get('/tingshuitz/xian', require('./routes/tingshuitz/xian')); +router.get('/tingshuitz/yangjiang', require('./routes/tingshuitz/yangjiang')); // MIUI 更新 router.get('/miui/:device/:type?/:region?', require('./routes/miui/index')); diff --git a/lib/routes/tingshuitz/guangzhou.js b/lib/routes/tingshuitz/guangzhou.js index e9440bcff..8b4b94b37 100644 --- a/lib/routes/tingshuitz/guangzhou.js +++ b/lib/routes/tingshuitz/guangzhou.js @@ -3,7 +3,7 @@ const cheerio = require('cheerio'); const iconv = require('iconv-lite'); module.exports = async (ctx) => { - const url = 'http://www.gzwatersupply.com/stop/stopgl.html2?tab=9'; + const url = 'http://www.gzwatersupply.com/stop/stopgl.html2'; const response = await axios({ responseType: 'arraybuffer', method: 'get', @@ -12,26 +12,24 @@ module.exports = async (ctx) => { const data = response.data; const $ = cheerio.load(iconv.decode(data, 'gb2312')); - const list = $('table') - .eq(37) - .find('tr'); + const list = $( + 'body > table:nth-child(2) > tbody:nth-child(2) > tr > td.border3 > table:nth-child(2) > tbody > tr:nth-child(1) > td:nth-child(2) > table > tbody > tr:nth-child(3) > td > table > tbody > tr > td > table > tbody > tr:nth-child(3) > td > table > tbody > tr' + ); ctx.state.data = { title: '停水通知 - 广州市自来水公司', - link: 'http://www.gzwatersupply.com/stop/stopgl.html2?tab=9', - item: - list && - list - .map((index, item) => { - item = $(item); + link: 'http://www.gzwatersupply.com/stop/stopgl.html2', + item: list + .map((index, item) => { + item = $(item); - const title = item.text(); - return { - title, - description: `广州市停水通知:${title}`, - link: `http://www.gzwatersupply.com/stop/${item.find('.new2').attr('href')}`, - }; - }) - .get(), + const title = item.text(); + return { + title, + description: `广州市停水通知:${title}`, + link: `http://www.gzwatersupply.com/stop/${item.find('.new2').attr('href')}`, + }; + }) + .get(), }; }; diff --git a/lib/routes/tingshuitz/xian.js b/lib/routes/tingshuitz/xian.js new file mode 100644 index 000000000..9caddd69e --- /dev/null +++ b/lib/routes/tingshuitz/xian.js @@ -0,0 +1,31 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const url = 'http://www.xazls.com/tsgg/index.htm'; + const response = await axios.get(url, { + responseType: 'arraybuffer', + }); + + const data = response.data; + const $ = cheerio.load(iconv.decode(data, 'gb2312')); + const list = $('#body > div.M > div.AboutUsDetail > ul > li'); + + ctx.state.data = { + title: $('title').text() || '停水通知 - 西安市自来水有限公司', + link: 'http://www.xazls.com/tsgg/index.htm', + item: list + .map((_, el) => { + const item = $(el); + + const a = item.find('a'); + return { + title: a.text().trim(), + description: item.text().trim(), + link: 'http://www.xazls.com' + a.attr('href'), + }; + }) + .get(), + }; +}; diff --git a/lib/routes/tingshuitz/yangjiang.js b/lib/routes/tingshuitz/yangjiang.js new file mode 100644 index 000000000..fbbdeea5a --- /dev/null +++ b/lib/routes/tingshuitz/yangjiang.js @@ -0,0 +1,40 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const url = 'http://www.yjsswjt.com/zxdt_list.jsp?flbz=7'; + const response = await axios.get(url, { + responseType: 'arraybuffer', + }); + + const data = response.data; + const $ = cheerio.load(iconv.decode(data, 'gb2312')); + const list = $('div.list_ul_div > ul > li'); + + ctx.state.data = { + title: '停水通知 - 阳江市水务集团有限公司', + link: 'http://www.yjsswjt.com/zxdt_list.jsp?flbz=7', + item: list + .map((_, el) => { + const item = $(el); + + const id = item + .find('a') + .attr('href') + .slice(17, -1); + return { + title: item + .find('span') + .text() + .trim(), + description: item + .find('span') + .text() + .trim(), + link: 'http://www.yjsswjt.com/list.jsp?id=' + id, + }; + }) + .get(), + }; +};