From c6b8ccf5c87e3d5d9fe13ca5ffb0dd67c885de38 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 29 Jan 2020 14:53:55 +0800 Subject: [PATCH] feat: coronavirus nhc --- docs/other.md | 2 +- lib/router.js | 2 +- lib/routes/coronavirus/nhc.js | 30 ++++++++++++++++++++++++++++++ lib/routes/nhc/list_gzbd.js | 35 ----------------------------------- 4 files changed, 32 insertions(+), 37 deletions(-) create mode 100644 lib/routes/coronavirus/nhc.js delete mode 100644 lib/routes/nhc/list_gzbd.js diff --git a/docs/other.md b/docs/other.md index 4bba03e2ec..ee0352cf9c 100644 --- a/docs/other.md +++ b/docs/other.md @@ -392,7 +392,7 @@ type 为 all 时,category 参数不支持 cost 和 free ### 国家卫健委 - 疫情通报 - + ### 财新网 - 武汉肺炎防疫全纪录 diff --git a/lib/router.js b/lib/router.js index b4ab4e2bd3..95300e5248 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/coronavirus/nhc.js b/lib/routes/coronavirus/nhc.js new file mode 100644 index 0000000000..8c6ba20d0c --- /dev/null +++ b/lib/routes/coronavirus/nhc.js @@ -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(), + }; +}; diff --git a/lib/routes/nhc/list_gzbd.js b/lib/routes/nhc/list_gzbd.js deleted file mode 100644 index 1c30c47408..0000000000 --- a/lib/routes/nhc/list_gzbd.js +++ /dev/null @@ -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, - }; -};