From ef3ed0e5c123671d000983cab89f53ec14d00257 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 7 Jul 2020 17:28:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E9=87=8D=E5=BA=86=E5=B8=82?= =?UTF-8?q?=E4=B8=A4=E6=B1=9F=E6=96=B0=E5=8C=BA=E4=BF=A1=E6=81=AF=E5=85=AC?= =?UTF-8?q?=E5=BC=80=E7=BD=91=20(#5130)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/government.md | 18 +++++++ lib/router.js | 4 ++ lib/routes/gov/chongqing/ljxq/dwgk.js | 48 +++++++++++++++++++ lib/routes/gov/chongqing/ljxq/zwgk.js | 68 +++++++++++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 lib/routes/gov/chongqing/ljxq/dwgk.js create mode 100644 lib/routes/gov/chongqing/ljxq/zwgk.js diff --git a/docs/government.md b/docs/government.md index 606303a1f..07a048e7e 100644 --- a/docs/government.md +++ b/docs/government.md @@ -433,6 +433,24 @@ pageClass: routes +## 重庆市人民政府 + +### 两江新区信息公开网 + +#### 党务公开 + + + +#### 政务公开 + + + +| 履职依据 | 公示公告 | +| -------- | -------- | +| lzyj | gsgg | + + + ## 中央纪委国家监委 ### 审查调查 diff --git a/lib/router.js b/lib/router.js index 7e3240ebe..a5f0f09ae 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2932,6 +2932,10 @@ router.get('/gelonghui/keyword/:keyword', require('./routes/gelonghui/keyword')) // 光谷社区 router.get('/guanggoo/:caty', require('./routes/guanggoo/index')); +// 重庆市两江新区信息公开网 +router.get('/gov/chongqing/ljxq/dwgk', require('./routes/gov/chongqing/ljxq/dwgk')); +router.get('/gov/chongqing/ljxq/zwgk/:caty', require('./routes/gov/chongqing/ljxq/zwgk')); + // 国家突发事件预警信息发布网 router.get('/12379', require('./routes/12379/index')); diff --git a/lib/routes/gov/chongqing/ljxq/dwgk.js b/lib/routes/gov/chongqing/ljxq/dwgk.js new file mode 100644 index 000000000..f9a339715 --- /dev/null +++ b/lib/routes/gov/chongqing/ljxq/dwgk.js @@ -0,0 +1,48 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'http://ljxq.cq.gov.cn/dwgk/'; + + const response = await got({ + method: 'get', + url: rootUrl, + }); + const $ = cheerio.load(response.data); + const list = $('div.gl-c-r-content ul li') + .slice(0, 10) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + + return { + title: a.text(), + link: url.resolve(rootUrl, a.attr('href')), + pubDate: new Date(item.find('span').text() + ' GMT+8').toUTCString(), + }; + }) + .get(); + + const items = 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('div.zwxl-article').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: '两江新区信息公开网 - 党务公开', + link: rootUrl, + item: items, + }; +}; diff --git a/lib/routes/gov/chongqing/ljxq/zwgk.js b/lib/routes/gov/chongqing/ljxq/zwgk.js new file mode 100644 index 000000000..fbd87715e --- /dev/null +++ b/lib/routes/gov/chongqing/ljxq/zwgk.js @@ -0,0 +1,68 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const rootUrl = 'http://ljxq.cq.gov.cn'; + +const config = { + lzyj: { + link: '/zwgk_199/fdzdgknr/zcwj/', + title: '履职依据', + }, + gsgg: { + link: '/zwgk_199/fdzdgknr/gggs/', + title: '公示公告', + }, +}; + +module.exports = async (ctx) => { + const cfg = config[ctx.params.caty]; + if (!cfg) { + throw Error('Bad category. See docs'); + } + + const currentUrl = url.resolve(rootUrl, cfg.link); + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + + $('tr.cwx-tit').remove(); + + const list = $('table.cwx-table tbody tr') + .slice(0, 10) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + + return { + title: a.text(), + link: url.resolve(currentUrl, a.attr('href')), + pubDate: new Date(item.find('td').eq(2).text() + ' GMT+8').toUTCString(), + }; + }) + .get(); + + const items = 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('div.zwxl-main').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: `两江新区信息公开网 - ${cfg.title}`, + link: rootUrl, + item: items, + }; +};