diff --git a/.gitignore b/.gitignore index 263c3a8b8..98d3d47cc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules npm-debug.log error.log combined.log +package-lock.json .vscode docs/.vuepress/dist diff --git a/README.md b/README.md index 2c77ced37..744046ea4 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,10 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 教务信息 - 新京报 - 快讯 +- 停水通知 + - 杭州市 + - 萧山区 + - 大连市 ## 鸣谢 diff --git a/docs/README.md b/docs/README.md index 140079bb6..16ea67f51 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1271,3 +1271,31 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到 路由: `/bjnews/:category` 参数: category,新京报的栏目名,点击对应栏目后在地址栏找到 + +## 停水通知 + +配合 [IFTTT](https://ifttt.com/) Applets [邮件通知](https://ifttt.com/applets/SEvmDVKY-) 使用实现自动通知效果 + +### 杭州市 + +举例: [https://rsshub.app/tingshuitz/hangzhou](https://rsshub.app/tingshuitz/hangzhou) + +路由: `/tingshuitz/hangzhou` + +参数: 无 + +### 萧山区 + +举例: [https://rsshub.app/tingshuitz/xiaoshan](https://rsshub.app/tingshuitz/xiaoshan) + +路由: `/tingshuitz/xiaoshan` + +参数: 无 + +### 大连市 + +举例: [https://rsshub.app/tingshuitz/dalian](https://rsshub.app/tingshuitz/dalian) + +路由: `/tingshuitz/dalian` + +参数: 无 diff --git a/router.js b/router.js index 7e5dedea8..15e419951 100644 --- a/router.js +++ b/router.js @@ -309,4 +309,9 @@ router.get('/shmtu/jwc/:type', require('./routes/shmtu/jwc')); // 新京报 router.get('/bjnews/:cat', require('./routes/bjnews/news')); +// 停水通知 +router.get('/tingshuitz/hangzhou', require('./routes/tingshuitz/hangzhou')); +router.get('/tingshuitz/xiaoshan', require('./routes/tingshuitz/xiaoshan')); +router.get('/tingshuitz/dalian', require('./routes/tingshuitz/dalian')); + module.exports = router; diff --git a/routes/tingshuitz/dalian.js b/routes/tingshuitz/dalian.js new file mode 100644 index 000000000..f188ff6cd --- /dev/null +++ b/routes/tingshuitz/dalian.js @@ -0,0 +1,38 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); + +module.exports = async (ctx) => { + //const area = ctx.params.area; + const url = `http://www.swj.dl.gov.cn/html/tstz/`; + const response = await axios({ + method: 'get', + url: url, + headers: { + 'User-Agent': config.ua, + }, + }); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('.listBox li'); + + ctx.state.data = { + title: $('title').text() || '停水通知 - 大连市水务局', + link: `http://www.swj.dl.gov.cn/html/tstz/`, + description: $('meta[name="description"]').attr('content') || $('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.find('span').text()).toUTCString(), + link: `${item.find('a').attr('href')}`, + }; + }) + .get(), + }; +}; diff --git a/routes/tingshuitz/hangzhou.js b/routes/tingshuitz/hangzhou.js new file mode 100644 index 000000000..d2f6f8075 --- /dev/null +++ b/routes/tingshuitz/hangzhou.js @@ -0,0 +1,38 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); + +module.exports = async (ctx) => { + //const area = ctx.params.area; + const url = `http://www.hzwgc.com/public/stop_the_water/`; + const response = await axios({ + method: 'get', + url: url, + headers: { + 'User-Agent': config.ua, + }, + }); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('.datalist li'); + + ctx.state.data = { + title: $('title').text(), + link: `http://www.hzwgc.com/public/stop_the_water/`, + description: $('meta[name="description"]').attr('content') || $('title').text(), + item: + list && + list + .map((index, item) => { + item = $(item); + return { + title: item.find('.title').text(), + description: `杭州市停水通知:${item.find('.title').text()}`, + pubDate: new Date(item.find('.published').text()).toUTCString(), + link: `http://www.hzwgc.com${item.find('.btn-read').attr('href')}`, + }; + }) + .get(), + }; +}; diff --git a/routes/tingshuitz/xiaoshan.js b/routes/tingshuitz/xiaoshan.js new file mode 100644 index 000000000..2024af286 --- /dev/null +++ b/routes/tingshuitz/xiaoshan.js @@ -0,0 +1,43 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); + +module.exports = async (ctx) => { + //const area = ctx.params.area; + const url = 'http://www.xswater.com/gongshui/channels/227.html'; + const response = await axios({ + method: 'get', + url: url, + headers: { + 'User-Agent': config.ua, + }, + }); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('.ul-list li'); + + ctx.state.data = { + title: $('title').text(), + link: `http://www.xswater.com/gongshui/channels/227.html`, + description: $('meta[name="description"]').attr('content') || $('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 + .find('span') + .text() + .slice(1, 11) + ).toUTCString(), + link: `http://www.xswater.com${item.find('a').attr('href')}`, + }; + }) + .get(), + }; +};