Navigation Menu

Skip to content

Commit

Permalink
feat: add route for beijing municipal health commission (#3952)
Browse files Browse the repository at this point in the history
  • Loading branch information
luyuhuang committed Feb 11, 2020
1 parent b277962 commit 621f3e9
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
10 changes: 10 additions & 0 deletions assets/radar-rules.js
Expand Up @@ -1237,4 +1237,14 @@
},
],
},
'beijing.gov.cn': {
wjw: [
{
title: '北京卫生健康委员会',
docs: 'https://docs.rsshub.app/government.html#zhong-yang-ji-wei-guo-jia-jian-wei',
source: '/xwzx_20031/:caty',
target: '/gov/beijing/mhc/:caty',
},
],
},
});
12 changes: 12 additions & 0 deletions docs/government.md
Expand Up @@ -4,6 +4,18 @@ pageClass: routes

# 政务消息

## 北京市卫生健康委员会

### 新闻中心

<Route author="luyuhuang" example="/gov/beijing/mhc/wnxw" path="/gov/beijing/mhc/:caty" :paramsDesc="['类别']">

| 委内新闻 | 基层动态 | 媒体聚焦 | 热点新闻 |
| :------: | :------: | :------: | :------: |
| wnxw | jcdt | mtjj | rdxws |

</Route>

## 国家新闻出版广电总局

### 游戏审批结果
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Expand Up @@ -1125,6 +1125,9 @@ router.get('/gov/fmprc/fyrbt', require('./routes/gov/fmprc/fyrbt'));
// 国家新闻出版广电总局
router.get('/gov/sapprft/approval/:channel/:detail?', require('./routes/gov/sapprft/7026'));

// 北京卫生健康委员会
router.get('/gov/beijing/mhc/:caty', require('./routes/gov/beijing/mhc'));

// 小黑盒
router.get('/xiaoheihe/user/:id', require('./routes/xiaoheihe/user'));
router.get('/xiaoheihe/news', require('./routes/xiaoheihe/news'));
Expand Down
69 changes: 69 additions & 0 deletions lib/routes/gov/beijing/mhc.js
@@ -0,0 +1,69 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');

const root_url = 'http://wjw.beijing.gov.cn/';

const config = {
wnxw: {
link: '/xwzx_20031/wnxw/',
title: '委内新闻',
},
jcdt: {
link: '/xwzx_20031/jcdt/',
title: '基层动态',
},
mtjj: {
link: '/xwzx_20031/mtjj/',
title: '媒体聚焦',
},
rdxws: {
link: '/xwzx_20031/rdxws/',
title: '热点新闻',
},
};

module.exports = async (ctx) => {
const cfg = config[ctx.params.caty];
if (!cfg) {
throw Error('Bad category. See <a href="https://docs.rsshub.app/government.html#zhong-yang-ji-wei-guo-jia-jian-wei">docs</a>');
}

const current_url = url.resolve(root_url, cfg.link);
const response = await got({
method: 'get',
url: current_url,
});
const $ = cheerio.load(response.data);
const list = $('div.weinei_left_con div.weinei_left_con_line')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const a = item.find('a[title]');
return {
title: a.text(),
link: url.resolve(current_url, a.attr('href')),
pubDate: new Date(item.find('div.weinei_left_con_line_date').text() + ' GMT+8').toUTCString(),
};
})
.get();

const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const res = await got({ method: 'get', url: item.link });
const content = cheerio.load(res.data);

item.description = content('div.weinei_left').html();
return item;
})
)
);

ctx.state.data = {
title: '北京卫健委 - ' + cfg.title,
link: root_url,
item: items,
};
};

0 comments on commit 621f3e9

Please sign in to comment.