diff --git a/docs/government.md b/docs/government.md index 203a5a698..aee9c1703 100644 --- a/docs/government.md +++ b/docs/government.md @@ -148,7 +148,13 @@ pageClass: routes ### 政府公开信息 - + + +| 法定主动内容 | 公示公告 | +|:--------:|:----:| +| fdzdnr | gsgg | + + ## 广东省人民政府 diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 1f0f25df7..32f2a9aaa 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -72,7 +72,7 @@ module.exports = { '/shenzhen/hrss/szksy/:caty/:page?': ['zlasd'], '/shenzhen/xxgk/zfxxgj/:caty': ['laoxua'], '/shenzhen/zzb/:caty/:page?': ['zlasd'], - '/sichuan/deyang/govpulicinfo/:countyName': ['zytomorrow'], + '/sichuan/deyang/govpublicinfo/:countyName/:infoType?': ['zytomorrow'], '/taiyuan/rsj/:caty/:page?': ['2PoL'], '/wuhan/sy/whyw': ['nczitzk'], '/xinyi/:path+': ['ShuiHuo'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index c300deee8..563a34b8f 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -443,7 +443,7 @@ module.exports = { title: '德阳市政府公开信息', docs: 'https://docs.rsshub.app/government.html#de-yang-shi-fu-ren-min-zheng-zheng-fu', source: ['/*'], - target: '/sichuan/deyang/govpulicinfo/:countyName', + target: '/sichuan/deyang/govpublicinfo/:countyName', }, ], }, diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 811553fe8..09505bced 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -63,7 +63,7 @@ module.exports = function (router) { router.get('/shenzhen/hrss/szksy/:caty/:page?', require('./shenzhen/hrss/szksy/index')); router.get('/shenzhen/xxgk/zfxxgj/:caty', require('./shenzhen/xxgk/zfxxgj')); router.get('/shenzhen/zzb/:caty/:page?', require('./shenzhen/zzb/index')); - router.get('/sichuan/deyang/govpulicinfo/:countyName', require('./sichuan/deyang/govpulicinfo')); + router.get('/sichuan/deyang/govpublicinfo/:countyName/:infoType?', require('./sichuan/deyang/govpublicinfo')); router.get('/taiyuan/rsj/:caty/:page?', require('./taiyuan/rsj')); router.get('/wuhan/sy/whyw', require('./wuhan/whyw')); router.get(/xinyi(\/[\w/-]+)?/, require('./xinyi/xinyi')); diff --git a/lib/v2/gov/sichuan/deyang/govpublicinfo.js b/lib/v2/gov/sichuan/deyang/govpublicinfo.js new file mode 100644 index 000000000..b7a7bedd1 --- /dev/null +++ b/lib/v2/gov/sichuan/deyang/govpublicinfo.js @@ -0,0 +1,88 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); +const timezone = require('@/utils/timezone'); + +// 各地区url信息 +const basicInfoDict = { + 绵竹市: { + rootUrl: 'https://www.mz.gov.cn', + infoType: { + fdzdnr: { + basicUrl: 'https://www.mz.gov.cn/info/iList.jsp?node_id=GKmzs&cat_id=15971&cur_page=1', + name: '法定主动内容', + }, + gsgg: { + basicUrl: 'https://www.mz.gov.cn/info/iList.jsp?node_id=GKmzs&cat_id=24186&cur_page=1', + name: '公示公告', + }, + }, + }, +}; + +const getInfoUrlList = async (rootUrl, infoBasicUrl) => { + const response = await got(infoBasicUrl); + const $ = cheerio.load(response.data); + // 非当前日期文章计数,部分旧文章可能会置顶,目前为发现置顶数超过10 + const infoList = $('body > div.container > div.ewb-white > div.ewb-job > ul > li').toArray().map((item) => ({ + title: $('a', item).attr('title'), + url: `${rootUrl}${$('a', item).attr('href')}`, + })); + return infoList; +}; + +// 获取信息正文内容 +const getInfoContent = (ctx, rootUrl, item) => + ctx.cache.tryGet(item.url, async () => { + const response = await got(item.url); + // 部分网页会跳转其他类型网站,则不解析,直接附超链接 + try { + const $ = cheerio.load(response.data); + const fileList = $('#symbol > div:nth-child(4) > div > span > a').toArray().map((item) => ({ + name: $(item).text(), + url: `${rootUrl}/${$(item).attr('href')}`, + })); + const rawDate = $('#symbol > div:nth-child(1) > div:nth-child(3)').text().split(':')[1].trim(); + return { + title: $('#main').text().trim(), + id: $('#symbol > div:nth-child(1) > div:nth-child(1)').text().split(':')[1].trim(), + infoNum: $('#symbol > div:nth-child(1) > div:nth-child(2) > span').text().split(':')[1].trim(), + pubDate: parseDate(timezone(rawDate, +8)), + date: rawDate, + keyWord: $('#symbol > div:nth-child(2) > div:nth-child(3)').text().split(':')[1].trim(), + source: $('#symbol > div:nth-child(2) > div:nth-child(2)').text().split(':')[1].trim(), + content: $('#container > div.ewb-white > div.ewb-article-detail').html(), + file: fileList, + link: item.url, + _isCompleteInfo: true, + }; + } catch (err) { + return { + title: item.title, + link: item.url, + _isCompleteInfo: false, + }; + } + }); + +module.exports = async (ctx) => { + const countyName = ctx.params.countyName; + const infoType = ctx.params.infoType || 'fdzdnr'; + const infoBasicUrl = basicInfoDict[countyName].infoType[infoType].basicUrl; + const rootUrl = basicInfoDict[countyName].rootUrl; + const infoUrlList = await getInfoUrlList(rootUrl, infoBasicUrl); + const items = await Promise.all(infoUrlList.map((item) => getInfoContent(ctx, rootUrl, item))); + + ctx.state.data = { + title: `政府公开信息-${countyName}-${basicInfoDict[countyName].infoType[infoType].name}`, + link: infoBasicUrl, + item: items.map((item) => ({ + title: item.title, + description: art(path.join(__dirname, './templates/govPublicInfo.art'), { item }), + link: item.link, + pubDate: item.pubDate, + })), + }; +}; diff --git a/lib/v2/gov/sichuan/deyang/govpulicinfo.js b/lib/v2/gov/sichuan/deyang/govpulicinfo.js deleted file mode 100644 index ae0126e0a..000000000 --- a/lib/v2/gov/sichuan/deyang/govpulicinfo.js +++ /dev/null @@ -1,95 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); -const path = require('path'); - -// 各地区url信息 -const basicInfoDict = { - 绵竹市: { - rootUrl: 'https://www.mz.gov.cn', - infoUrl: 'https://www.mz.gov.cn/info/iList.jsp?tm_id=1805&cur_page=', - }, -}; - -const getInfoUrlList = async (countyName) => { - const url = basicInfoDict[countyName].infoUrl; - const infoUrlList = []; - const expectToday = new Date(); - for (let pageNum = 1; ; pageNum++) { - let response; - try { - // eslint-disable-next-line no-await-in-loop - response = await got(`${url}${pageNum}`); - } catch (err) { - // eslint-disable-next-line no-await-in-loop - response = await got(`${url}${pageNum}`, { dnsLookupIpVersion: 'ipv6' }); - } - const $ = cheerio.load(response.data); - const infoList = $('#list_content > ul > li'); - // 判断当前页是否有数据 - if (infoList.length !== 0) { - for (let infoIdx = 0; infoIdx < infoList.length; infoIdx++) { - const date = parseDate($('span', infoList[infoIdx]).html()); - // 判断当前信息日期是否是今日 - if (date.getUTCFullYear() === expectToday.getUTCFullYear() && date.getUTCMonth() === expectToday.getUTCMonth() && date.getUTCDate() === expectToday.getUTCDate() - 1) { - infoUrlList.push(`${basicInfoDict[countyName].rootUrl}${$('a', infoList[infoIdx]).attr('href')}`); - } else { - return infoUrlList; - } - } - } else { - return infoUrlList; - } - } -}; - -// 获取信息正文内容 -const getInfoContent = (ctx, url, countyName) => - ctx.cache.tryGet(url, async () => { - let response; - try { - response = await got(url); - } catch (err) { - response = await got(url, { dnsLookupIpVersion: 'ipv6' }); - } - const $ = cheerio.load(response.data); - const fileNodes = $('#symbol > div:nth-child(4) > div > span > a'); - const fileList = []; - for (let i = 0; i < fileNodes.length; i++) { - fileList.push({ - name: $(fileNodes[i]).text(), - url: `${basicInfoDict[countyName].rootUrl}/${$(fileNodes[i]).attr('href')}`, - }); - } - const rawDate = $('#symbol > div:nth-child(1) > div:nth-child(3)').text().split(':')[1].trim(); - return { - title: $('#main').text().trim(), - id: $('#symbol > div:nth-child(1) > div:nth-child(1)').text().split(':')[1].trim(), - infoNum: $('#symbol > div:nth-child(1) > div:nth-child(2) > span').text().split(':')[1].trim(), - pubDate: parseDate(rawDate), - date: rawDate, - keyWord: $('#symbol > div:nth-child(2) > div:nth-child(3)').text().split(':')[1].trim(), - source: $('#symbol > div:nth-child(2) > div:nth-child(2)').text().split(':')[1].trim(), - content: $('#container > div.ewb-white > div.ewb-article-detail').html(), - file: fileList, - link: url, - }; - }); - -module.exports = async (ctx) => { - const countyName = ctx.params.countyName; - const infoUrlList = await getInfoUrlList(countyName); - const items = await Promise.all(infoUrlList.map((item) => getInfoContent(ctx, item, countyName))); - - ctx.state.data = { - title: `政府公开信息 - ${countyName}`, - link: basicInfoDict[countyName].infoUrl, - item: items.map((item) => ({ - title: item.title, - description: art(path.resolve(__dirname, './templates/govPublicInfo.art'), { item }), - link: item.link, - pubDate: item.pubDate, - })), - }; -}; diff --git a/lib/v2/gov/sichuan/deyang/templates/govPublicInfo.art b/lib/v2/gov/sichuan/deyang/templates/govPublicInfo.art index b05297b31..2df8c9b38 100644 --- a/lib/v2/gov/sichuan/deyang/templates/govPublicInfo.art +++ b/lib/v2/gov/sichuan/deyang/templates/govPublicInfo.art @@ -1,42 +1,47 @@ - - - - - - - - - - - - - - - - - - - - - - - {{if item.file.length}} +{{if item._isCompleteInfo}} +
索引号{{item.id}}
文号{{item.infoNum}}
发文日期{{item.date}}
关键词{{item.keyWord}}
信息来源{{item.source}}
+ - - + + - {{/if}} - -
附件 - {{each item.file}} - {{$value.name}}
- {{/each}} -
索引号{{item.id}}
- -
-
- {{@ item.content}} -
+ + 文号 + {{item.infoNum}} + + + 发文日期 + {{item.date}} + + + 关键词 + {{item.keyWord}} + + + 信息来源 + {{item.source}} + + {{if item.file.length}} + + 附件 + + {{each item.file}} + {{$value.name}}
+ {{/each}} + + + {{/if}} + + +
+
+ {{@ item.content }} +
+{{else}} +
+ {{item.title}} +
+{{/if}}