feat: coronavirus nhc

This commit is contained in:
DIYgod
2020-01-29 14:53:55 +08:00
parent c2bbf19a9f
commit c6b8ccf5c8
4 changed files with 32 additions and 37 deletions

View File

@@ -392,7 +392,7 @@ type 为 all 时category 参数不支持 cost 和 free
### 国家卫健委 - 疫情通报
<Route author="Cielpy" example="/nhc/list_gzbd" path="/nhc/list_gzbd"/>
<Route author="Cielpy" example="coronavirus/nhc" path="/coronavirus/nhc"/>
### 财新网 - 武汉肺炎防疫全纪录

View File

@@ -2159,6 +2159,6 @@ router.get('/coronavirus/dxy/data/:province', require('./routes/coronavirus/dxy-
router.get('/coronavirus/dxy/data', require('./routes/coronavirus/dxy-data-country'));
router.get('/coronavirus/dxy', require('./routes/coronavirus/dxy'));
router.get('/coronavirus/scmp', require('./routes/coronavirus/scmp'));
router.get('/nhc/list_gzbd', require('./routes/nhc/list_gzbd'));
router.get('/coronavirus/nhc', require('./routes/coronavirus/nhc'));
module.exports = router;

View File

@@ -0,0 +1,30 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const url = `http://www.nhc.gov.cn/xcs/yqtb/list_gzbd.shtml`;
const res = await got.get(url);
const $ = cheerio.load(res.data);
const list = $('.zxxx_list a');
ctx.state.data = {
title: '疫情通报-国家卫健委',
link: url,
item:
list &&
list
.map((index, item) => {
item = $(item);
const title = item.text();
const address = item.attr('href');
const host = `http://www.nhc.gov.cn/`;
return {
title,
description: title,
link: host + address,
guid: host + address,
};
})
.get(),
};
};

View File

@@ -1,35 +0,0 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const url = `http://www.nhc.gov.cn/xcs/yqtb/list_gzbd.shtml`;
const res = await got.get(url);
const $ = cheerio.load(res.data);
const list = $('.zxxx_list a').get();
const out = await Promise.all(
list.splice(0, 10).map(async (item) => {
const $ = cheerio.load(item);
const title = $(item).text();
const address = $(item).attr('href');
const cache = await ctx.cache.get(address);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const host = `http://www.nhc.gov.cn/`;
const single = {
title,
description: title,
link: host + address,
guid: host + address,
};
ctx.cache.set(address, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '疫情通报-国家卫健委',
link: url,
item: out,
};
};