From 217a9a5dba05d693deda067819bf02f940d75ab2 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Wed, 6 May 2020 19:46:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=B8=AD=E5=8D=8E=E4=BA=BA?= =?UTF-8?q?=E6=B0=91=E5=85=B1=E5=92=8C=E5=9B=BD=E4=BD=8F=E6=88=BF=E5=92=8C?= =?UTF-8?q?=E5=9F=8E=E4=B9=A1=E5=BB=BA=E8=AE=BE=E9=83=A8=E6=94=BF=E7=AD=96?= =?UTF-8?q?=E5=8F=91=E5=B8=83=20(#4647)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/government.md | 6 +++++ lib/router.js | 3 +++ lib/routes/gov/mohurd/policy.js | 40 +++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 lib/routes/gov/mohurd/policy.js diff --git a/docs/government.md b/docs/government.md index 9be177583..72896876f 100644 --- a/docs/government.md +++ b/docs/government.md @@ -375,6 +375,12 @@ pageClass: routes +## 中华人民共和国住房和城乡建设部 + +### 政策发布 + + + ## 中央纪委国家监委 ### 审查调查 diff --git a/lib/router.js b/lib/router.js index 511128db1..1ac64996a 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1172,6 +1172,9 @@ router.get('/gov/moe/:type', require('./routes/gov/moe/moe')); // 中华人民共和国外交部 router.get('/gov/fmprc/fyrbt', require('./routes/gov/fmprc/fyrbt')); +// 中华人民共和国住房和城乡建设部 +router.get('/gov/mohurd/policy', require('./routes/gov/mohurd/policy')); + // 国家新闻出版广电总局 router.get('/gov/sapprft/approval/:channel/:detail?', require('./routes/gov/sapprft/7026')); diff --git a/lib/routes/gov/mohurd/policy.js b/lib/routes/gov/mohurd/policy.js new file mode 100644 index 000000000..946f3b8e1 --- /dev/null +++ b/lib/routes/gov/mohurd/policy.js @@ -0,0 +1,40 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = `http://www.mohurd.gov.cn/wjfb/index.html`; + const response = await got({ method: 'get', url: link }); + + const $ = cheerio.load(response.data); + const list = $('body table tbody tr') + .eq(3) + .find('td table tbody tr') + .eq(2) + .find('td table tbody tr') + .map((_, item) => { + const a = $(item).find('a'); + const subtitle = $(item).find('td').eq(2).text(); + return { + title: a.text() + (subtitle === '' ? '' : ' - ' + subtitle), + link: a.attr('href'), + pubDate: new Date($(item).find('td').eq(3).text().substr(1, 10) + ' GMT+8').toUTCString(), + }; + }) + .get(); + + ctx.state.data = { + title: '中华人民共和国住房和城乡建设部 - 政策发布', + link: link, + item: await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ method: 'get', url: item.link }); + const content = cheerio.load(detailResponse.data); + item.description = content('table[bgcolor="#ffffff"]').html(); + return item; + }) + ) + ), + }; +};