From b38201a63a4361ea238586f0bcd25fdd805b5a56 Mon Sep 17 00:00:00 2001 From: Victorique Ko Date: Tue, 23 Oct 2018 23:59:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E5=81=9C=E6=B0=B4?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=20-=20=E4=B8=9C=E8=8E=9E=E5=B8=82=20(#944)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 ++ router.js | 1 + routes/tingshuitz/dongguan.js | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 routes/tingshuitz/dongguan.js diff --git a/docs/README.md b/docs/README.md index fb192ecd2..8121c49c1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1468,6 +1468,8 @@ Category 列表: + + ### 中央气象台 diff --git a/router.js b/router.js index 8d71c3d9d..ca0d4c0f2 100644 --- a/router.js +++ b/router.js @@ -335,6 +335,7 @@ router.get('/tingshuitz/hangzhou', require('./routes/tingshuitz/hangzhou')); 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')); // MIUI 更新 router.get('/miui/:device/:type?', require('./routes/miui/index')); diff --git a/routes/tingshuitz/dongguan.js b/routes/tingshuitz/dongguan.js new file mode 100644 index 000000000..9a48fca65 --- /dev/null +++ b/routes/tingshuitz/dongguan.js @@ -0,0 +1,37 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const url = 'http://www.djsw.com.cn/news/tstz/index.html'; + const response = await axios({ + method: 'get', + url, + }); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('#cntR li'); + + ctx.state.data = { + title: $('title').text() || '停水通知 - 东莞市东江水务有限公司', + link: 'http://www.djsw.com.cn/news/tstz/index.html', + description: $('title').text() || '停水通知 - 东莞市东江水务有限公司', + item: + list && + list + .map((index, item) => { + item = $(item); + return { + title: item.find('a').text(), + description: `东莞市停水通知:${item.find('a').text()}`, + pubDate: new Date( + $(item.contents()[1]) + .text() + .slice(1, -1) + ).toUTCString(), + link: item.find('a').attr('href'), + }; + }) + .get(), + }; +};