From 38676afb7378f0221d6222e9ea89cfdcca56359e Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Tue, 16 Jul 2019 11:13:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=B8=AD=E5=A4=AE=E7=BA=AA?= =?UTF-8?q?=E5=A7=94=E5=9B=BD=E5=AE=B6=E7=9B=91=E5=A7=94=E5=AE=A1=E6=9F=A5?= =?UTF-8?q?=E8=B0=83=E6=9F=A5=20(#2614)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add 中央纪委国家监委审查调查 * no cache time Co-authored-by: DIYgod --- docs/government.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/ccdi/scdc.js | 47 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 lib/routes/ccdi/scdc.js diff --git a/docs/government.md b/docs/government.md index 984537e52..e9f44990e 100644 --- a/docs/government.md +++ b/docs/government.md @@ -198,6 +198,12 @@ pageClass: routes +## 中央纪委国家监委 + +### 审查调查 + + + ## 中华人民共和国外交部 ### 发言人表态 diff --git a/lib/router.js b/lib/router.js index d36f489e3..debcd00b3 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1495,6 +1495,9 @@ router.get('/aptonic/action', require('./routes/aptonic/action')); // 印记中文周刊 router.get('/docschina/jsweekly', require('./routes/docschina/jsweekly')); +// 中央纪委国家监委网站 +router.get('/ccdi/scdc', require('./routes/ccdi/scdc')); + // 香水时代 router.get('/nosetime/:id/:type/:sort?', require('./routes/nosetime/comment')); router.get('/nosetime/home', require('./routes/nosetime/home')); diff --git a/lib/routes/ccdi/scdc.js b/lib/routes/ccdi/scdc.js new file mode 100644 index 000000000..71d65007a --- /dev/null +++ b/lib/routes/ccdi/scdc.js @@ -0,0 +1,47 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { resolve } = require('url'); + +module.exports = async (ctx) => { + const url = 'http://www.ccdi.gov.cn/scdc/'; + const res = await got.get(url); + const $ = cheerio.load(res.data); + + const list = $('ul.list_news_dl.fixed li'); + const out = await Promise.all( + list + .map(async (index, elem) => { + elem = $(elem); + const title = elem.find('a').text(); + const link = resolve(url, elem.find('a').attr('href')); + const pubDate = new Date(elem.find('span').text()).toUTCString(); + + const item = { + title, + pubDate, + link, + }; + + const key = link; + const value = await ctx.cache.get(key); + if (value) { + item.description = value; + } else { + const response = await got.get(item.link); + const data = response.data; + const $ = cheerio.load(data); + item.description = $('div.TRS_Editor').html(); + ctx.cache.set(key, item.description); + } + + return Promise.resolve(item); + }) + .get() + ); + + ctx.state.data = { + title: '中央纪委国家监委-审查调查', + link: url, + item: out, + }; +};