diff --git a/docs/government.md b/docs/government.md
index 835bc8e1b..07cb278c7 100644
--- a/docs/government.md
+++ b/docs/government.md
@@ -96,7 +96,7 @@ pageClass: routes
### 德阳市政府公开信息
-
+
## 广东省人民政府
diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js
index 9d45bbee4..d74140d0d 100644
--- a/lib/v2/gov/maintainer.js
+++ b/lib/v2/gov/maintainer.js
@@ -8,7 +8,7 @@ module.exports = {
'/guangdong/tqyb/tfxtq': ['Fatpandac'],
'/guangdong/tqyb/sncsyjxh': ['Fatpandac'],
'/huizhou/zwgk/:category?': ['Fatpandac'],
- '/sichuan/deyang/govpulicinfo/:countyName/:institutionName?': ['zytomorrow'],
+ '/sichuan/deyang/govpulicinfo/:countyName': ['zytomorrow'],
'/mfa/wjdt/:category?': ['nczitzk'],
'/miit/wjfb/:ministry': ['Fatpandac'],
'/miit/yjzj': ['Fatpandac'],
diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js
index b918b79d8..89a973afe 100644
--- a/lib/v2/gov/radar.js
+++ b/lib/v2/gov/radar.js
@@ -296,7 +296,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/:institutionName?',
+ target: '/sichuan/deyang/govpulicinfo/:countyName',
},
],
},
diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js
index 9764fed41..e539b2030 100644
--- a/lib/v2/gov/router.js
+++ b/lib/v2/gov/router.js
@@ -9,7 +9,7 @@ module.exports = function (router) {
router.get('/guangdong/tqyb/tfxtq', require('./guangdong/tqyb/tfxtq'));
router.get('/guangdong/tqyb/sncsyjxh', require('./guangdong/tqyb/sncsyjxh'));
router.get('/huizhou/zwgk/:category?', require('./huizhou/zwgk/index'));
- router.get('/sichuan/deyang/govpulicinfo/:countyName/:institutionName?', require('./sichuan/deyang/govpulicinfo'));
+ router.get('/sichuan/deyang/govpulicinfo/:countyName', require('./sichuan/deyang/govpulicinfo'));
router.get('/mfa/wjdt/:category?', require('./mfa/wjdt'));
router.get('/miit/wjfb/:ministry', require('./miit/wjfb'));
router.get('/miit/yjzj', require('./miit/yjzj'));
diff --git a/lib/v2/gov/sichuan/deyang/govpulicinfo.js b/lib/v2/gov/sichuan/deyang/govpulicinfo.js
index 84db4fcf2..761c08657 100644
--- a/lib/v2/gov/sichuan/deyang/govpulicinfo.js
+++ b/lib/v2/gov/sichuan/deyang/govpulicinfo.js
@@ -3,112 +3,82 @@ const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
+const timezone = require('@/utils/timezone');
-const rootUrl = 'http://xxgk.deyang.gov.cn/xxgkml2020';
-
-// 地区名称对照表
-const nameDict = {
- 德阳市: 'dys',
- 绵竹市: 'mzs',
- 什邡市: 'sfs',
- 旌阳区: 'jyq',
- 罗江区: 'ljx',
- 广汉市: 'ghs',
- 中江县: 'zjx',
- 高新区: 'gxq',
+// 各地区url信息
+const basicInfoDict = {
+ 绵竹市: {
+ rootUrl: 'https://www.mz.gov.cn',
+ infoUrl: 'https://www.mz.gov.cn/info/iList.jsp?tm_id=1805&cur_page=',
+ },
};
-const getInstitutionId = async (ctx, county) => {
- const url = `${rootUrl}/ptlj.jsp?regionName=${county}`;
-
- return await ctx.cache.tryGet(`${county}InstitutionId`, async () => {
- const response = await got.get(url);
+const getInfoUrlList = async (countyName) => {
+ const url = basicInfoDict[countyName].infoUrl;
+ const infoUrlList = [];
+ const expectToday = parseDate(timezone(new Date(), +8));
+ for (let pageNum = 1; ; pageNum++) {
+ // eslint-disable-next-line no-await-in-loop
+ const response = await got(`${url}${pageNum}`);
const $ = cheerio.load(response.data);
- const dataList = $('#details_content > div > div > div > div:nth-child(4) > ul > li > a');
- const _tmp = {};
- for (let i = 0; i < dataList.length; i++) {
- _tmp[$(dataList[i]).html()] = parseInt($(dataList[i]).attr('href').split('deptId=')[1]);
+ 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.getUTCDay() === expectToday.getUTCDay()) {
+ infoUrlList.push(`${basicInfoDict[countyName].rootUrl}${$('a', infoList[infoIdx]).attr('href')}`);
+ } else {
+ return infoUrlList;
+ }
+ }
+ } else {
+ return infoUrlList;
}
- return _tmp;
- });
+ }
};
-const getInfoUrlList = async (county, institutionId) => {
- const url = `${rootUrl}/gklist_iframe.jsp?deptId=${institutionId}®ionName=${county}&pageSize=15`;
- const response = await got.get(url);
- const $ = cheerio.load(response.data);
- const pageNum = parseInt($('#list_content > div > span:nth-child(3)').html().match(/\d*/g)[1]);
- const pageUrlList = [];
-
- // 此处建议限制最大pageNum,最大5页,单页15条
- for (let i = 1; i <= Math.min(pageNum, 5); i++) {
- pageUrlList.push(`${rootUrl}/gklist_iframe.jsp?deptId=${institutionId}®ionName=${county}&pageSize=15$pageIndex=${i}`);
- }
- const _tmpList = await Promise.all(
- pageUrlList.map(async (url) => {
- const response = await got.get(url);
- const $ = cheerio.load(response.data);
- const InfoList = $('#list_content > ul > li > a');
- return InfoList.map((item) => `${rootUrl}/${$(InfoList[item]).attr('href')}`);
- })
- );
- let infoUrlList = [];
- for (let i = 0; i < _tmpList.length; i++) {
- infoUrlList = infoUrlList.concat(_tmpList[i].toArray());
- }
- return infoUrlList;
-};
-
-const getInfoContent = async (ctx, url) => {
- const infoId = url.split('id=')[1].split('&type')[0];
- return await ctx.cache.tryGet(`govPublicInfo${infoId}`, async () => {
- const response = await got.get(url);
+// 获取信息正文内容
+const getInfoContent = async (ctx, url, countyName) =>
+ await ctx.cache.tryGet(url, async () => {
+ const response = await got(url);
const $ = cheerio.load(response.data);
- const fileNodes = $('#symbol > div:nth-child(3) > div > a');
+ 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: `${rootUrl}/${$(fileNodes[i]).attr('href')}`,
+ url: `${basicInfoDict[countyName].rootUrl}/${$(fileNodes[i]).attr('href')}`,
});
}
- const rawDate = $('#symbol > div:nth-child(1) > div:nth-child(3)').text().split('\n')[1].trim();
+ const rawDate = $('#symbol > div:nth-child(1) > div:nth-child(3)').text().split(':')[1].trim();
return {
- title: $('#headline').text(),
- id: infoId,
- infoNum: $('#symbol > div:nth-child(1) > div:nth-child(2) > span').text().split('\n')[1].trim(),
+ 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(1)').text().slice(8),
- source: $('#symbol > div:nth-child(2) > div:nth-child(3)').text().slice(5),
- content: $('#details_content > div.content').html(),
+ 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 county = nameDict[countyName];
- const institutionName = ctx.params.institutionName || '';
- let institutionId = 0;
- if (institutionName) {
- const institutionDict = await getInstitutionId(ctx, county);
- institutionId = institutionDict[institutionName];
- }
-
- const infoUrlList = await getInfoUrlList(county, institutionId);
+ const infoUrlList = await getInfoUrlList(countyName);
const items = await Promise.all(infoUrlList.map(async (item) => await getInfoContent(ctx, item)));
ctx.state.data = {
- title: `政府公开信息 - ${countyName} ${institutionName}`,
- link: `${rootUrl}/gklist_iframe.jsp?deptId=${institutionId}®ionName=${county}`,
+ 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,
- guid: item.id,
pubDate: item.pubDate,
})),
};
diff --git a/lib/v2/gov/sichuan/deyang/templates/govPublicInfo.art b/lib/v2/gov/sichuan/deyang/templates/govPublicInfo.art
index e8b9284b6..b05297b31 100644
--- a/lib/v2/gov/sichuan/deyang/templates/govPublicInfo.art
+++ b/lib/v2/gov/sichuan/deyang/templates/govPublicInfo.art
@@ -33,6 +33,7 @@
+
{{@ item.content}}