Skip to content

Commit

Permalink
添加 停水通知 (DIYgod#315)
Browse files Browse the repository at this point in the history
* Add tingshuitz in Hanghou, Xiaoshan, Dalian area

* 更新 停水通知 文档

* 更正文档链接错误处

* Remove package-lock.json

* Change .gitignore
  • Loading branch information
znhocn authored and DIYgod committed Jun 27, 2018
1 parent c0444c8 commit 3d63c2f
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules
npm-debug.log
error.log
combined.log
package-lock.json
.vscode
docs/.vuepress/dist

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 教务信息
- 新京报
- 快讯
- 停水通知
- 杭州市
- 萧山区
- 大连市

## 鸣谢

Expand Down
28 changes: 28 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

参数: 无
5 changes: 5 additions & 0 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
38 changes: 38 additions & 0 deletions routes/tingshuitz/dalian.js
Original file line number Diff line number Diff line change
@@ -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(),
};
};
38 changes: 38 additions & 0 deletions routes/tingshuitz/hangzhou.js
Original file line number Diff line number Diff line change
@@ -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(),
};
};
43 changes: 43 additions & 0 deletions routes/tingshuitz/xiaoshan.js
Original file line number Diff line number Diff line change
@@ -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(),
};
};

0 comments on commit 3d63c2f

Please sign in to comment.