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, + }; +};