From 6bbfc9014c19ad56e3c096c7e2047f0bb38c70cd Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 29 Jan 2020 14:45:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=9B=BD=E5=AE=B6?= =?UTF-8?q?=E5=8D=AB=E5=81=A5=E5=A7=94=E7=96=AB=E6=83=85=E9=80=9A=E6=8A=A5?= =?UTF-8?q?=20(#3826)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/other.md | 4 ++++ lib/router.js | 1 + lib/routes/nhc/list_gzbd.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 lib/routes/nhc/list_gzbd.js diff --git a/docs/other.md b/docs/other.md index 78c94d0af1..4bba03e2ec 100644 --- a/docs/other.md +++ b/docs/other.md @@ -390,6 +390,10 @@ type 为 all 时,category 参数不支持 cost 和 free ## 武汉肺炎疫情新闻动态 +### 国家卫健委 - 疫情通报 + + + ### 财新网 - 武汉肺炎防疫全纪录 diff --git a/lib/router.js b/lib/router.js index ecbd39c3a5..b4ab4e2bd3 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2159,5 +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')); module.exports = router; diff --git a/lib/routes/nhc/list_gzbd.js b/lib/routes/nhc/list_gzbd.js new file mode 100644 index 0000000000..2b077901f6 --- /dev/null +++ b/lib/routes/nhc/list_gzbd.js @@ -0,0 +1,35 @@ +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.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, + }; +};