fix(route): sichuan/deyang 政府公开信息 (#9453)
* fead: add 雪球股票评论 * style: auto format * fix: 修复雪球评论转发时未带原文 * refactor: 微博个人时间线接入util,支持可读性优化,同时打开emoji表情展示 * route: 雪球评论标题长度自定义 * style: auto format * fix: 风之动漫域名更换 * fix: 风之漫画新域名适配 * refactor: 微博个人时间线接入util,支持可读性优化,同时打开emoji表情展示 * fix: 雪球股票评论格式调整 * fix: 风之动漫域名更换 * fix: 风之动漫link修复 * fix: 雪球股票评论正文使用art模板,日期解析调整 * feat(route): add 德阳考试中心 * feat(route): add 德阳考试中心 * fix: 风之动漫获取数量去掉限制 * fix: 风之动漫获取数量去掉限制 * fix: 风之动漫获取数量使用通用参数控制 * fix: 风之动漫获取数量使用通用参数控制 * style: auto format * fix: dykszx * fix: 德阳考试中心 ssl证书过期 * Merge branch 'master' of https://github.com/DIYgod/RSSHub into dykszx * Merge branch 'master' of https://github.com/DIYgod/RSSHub into dykszx * tmp1 * tmp2: * tmp3 * feat(route): add 政府公开信息 * feat(route): add 政府公开信息 * feat(route): add 政府公开信息 * feat(route): add 政府公开信息 * feat(route): add 政府公开信息 * Revert "feat(route): add 政府公开信息" This reverts commit c9d59af9e09b14f7357014382037b7f378d65ea7. * feat(route): add 政府公开信息 * fix: 修复德阳政府公开信息 * fix: 修复德阳政府公开信息 * Merge branch 'master' of https://github.com/DIYgod/RSSHub into fix_router * Merge branch 'master' of https://github.com/DIYgod/RSSHub into fix_router * Merge branch 'master' of https://github.com/DIYgod/RSSHub into fix_router * fix: 修复德阳政府公开信息 Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
co-authored by
GitHub Action
parent
5b7b2f449a
commit
476b3934bc
+1
-1
@@ -96,7 +96,7 @@ pageClass: routes
|
||||
|
||||
### 德阳市政府公开信息
|
||||
|
||||
<Route author="zytomorrow" example="/gov/sichuan/deyang/govpulicinfo/德阳市市/市人社局" path="/gov/sichuan/deyang/govpulicinfo/:countyName/:institutionName?" :paramsDesc="['区县名。德阳市、绵竹市、广汉市、什邡市、中江县、罗江区、旌阳区、高新区', '单位名称。可直接输入网页显示单位名称']"/>
|
||||
<Route author="zytomorrow" example="/gov/sichuan/deyang/govpulicinfo/绵竹市" path="/gov/sichuan/deyang/govpulicinfo/:countyName" :paramsDesc="['区县名(**其他区县整改中,暂时只支持`绵竹市`**)。德阳市、绵竹市、广汉市、什邡市、中江县、罗江区、旌阳区、高新区']"/>
|
||||
|
||||
## 广东省人民政府
|
||||
|
||||
|
||||
@@ -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'],
|
||||
|
||||
+1
-1
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -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'));
|
||||
|
||||
@@ -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,
|
||||
})),
|
||||
};
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr/>
|
||||
<div>
|
||||
{{@ item.content}}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user