Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add 国务院政策文件库 #11301

Merged
merged 4 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/government.md
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ pageClass: routes

<Route author="hillerliao" example="/csrc/auditstatus/:apply_id" path="/csrc/auditstatus" :paramsDesc="['事项类别id,`https://neris.csrc.gov.cn/alappl/home/xkDetail` 列表中各地址的 appMatrCde 参数']"/>

## 中国政府
## 中国政府网

### 数据

Expand Down Expand Up @@ -1040,7 +1040,7 @@ pageClass: routes

### 最新文件

<Route author="ciaranchen" example="/gov/zhengce/wenjian" path="/gov/zhengce/wenjian/:pcodeJiguan?" :paramsDesc="['文种分类。国令; 国发; 国函; 国发明电; 国办发; 国办函; 国办发明电; 其他']" />
<Route author="ciaranchen" example="/gov/zhengce/wenjian" path="/gov/zhengce/wenjian/:pcodeJiguan?" :paramsDesc="['文种分类。国令、国发、国函、国发明电国办发国办函国办发明电其他']" />

### 信息稿件

Expand All @@ -1059,6 +1059,10 @@ pageClass: routes

</Route>

### 国务院政策文件库

<Route author="zxx-457" example="/gov/zhengce/zhengceku/bmwj" path="/gov/zhengce/zhengceku/:department" :paramsDesc="['库名']" />

### 政府新闻

<Route author="EsuRt" example="/gov/news/:uid" path="/gov/news" :paramsDesc="['分类名']">
Expand Down
6 changes: 3 additions & 3 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1174,9 +1174,9 @@ router.get('/cyzone/author/:id', lazyloadRouteHandler('./routes/cyzone/author'))
router.get('/cyzone/label/:name', lazyloadRouteHandler('./routes/cyzone/label'));

// 政府
router.get('/gov/zhengce/zuixin', lazyloadRouteHandler('./routes/gov/zhengce/zuixin'));
router.get('/gov/zhengce/wenjian/:pcodeJiguan?', lazyloadRouteHandler('./routes/gov/zhengce/wenjian'));
router.get('/gov/zhengce/govall/:advance?', lazyloadRouteHandler('./routes/gov/zhengce/govall'));
// router.get('/gov/zhengce/zuixin', lazyloadRouteHandler('./routes/gov/zhengce/zuixin'));
// router.get('/gov/zhengce/wenjian/:pcodeJiguan?', lazyloadRouteHandler('./routes/gov/zhengce/wenjian'));
// router.get('/gov/zhengce/govall/:advance?', lazyloadRouteHandler('./routes/gov/zhengce/govall'));
router.get('/gov/province/:name/:category', lazyloadRouteHandler('./routes/gov/province'));
router.get('/gov/city/:name/:category', lazyloadRouteHandler('./routes/gov/city'));
router.get('/gov/statecouncil/briefing', lazyloadRouteHandler('./routes/gov/statecouncil/briefing'));
Expand Down
59 changes: 0 additions & 59 deletions lib/routes/gov/zhengce/govall.js

This file was deleted.

53 changes: 0 additions & 53 deletions lib/routes/gov/zhengce/wenjian.js

This file was deleted.

42 changes: 0 additions & 42 deletions lib/routes/gov/zhengce/zuixin.js

This file was deleted.

4 changes: 4 additions & 0 deletions lib/v2/gov/maintainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ module.exports = {
'/pbc/tradeAnnouncement': ['nczitzk'],
'/pbc/zcyj': ['Fatpandac'],
'/stats/:path+': ['bigfei'],
'/zhengce/govall/:advance?': ['ciaranchen'],
'/zhengce/wenjian/:pcodeJiguan?': ['ciaranchen'],
'/zhengce/zhengceku/:department': ['zxx-457'],
'/zhengce/zuixin': ['SettingDust'],
// province
'/anhui/kjt/:path?': ['nczitzk'],
'/beijing/bphc/:channel': ['bigfei'],
Expand Down
29 changes: 29 additions & 0 deletions lib/v2/gov/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,35 @@ module.exports = {
},
],
},
'www.gov.cn': {
_name: '中国政府网',
'.': [
{
title: '最新政策',
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zheng-fu-wang',
source: ['/zhengce/zuixin.htm', '/'],
target: '/gov/zhengce/zuixin',
},
{
title: '最新文件',
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zheng-fu-wang',
source: ['/'],
target: '/gov/zhengce/wenjian',
},
{
title: '信息稿件',
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zheng-fu-wang',
source: ['/'],
target: '/gov/zhengce/govall',
},
{
title: '国务院政策文件库',
docs: 'https://docs.rsshub.app/government.html#zhong-guo-zheng-fu-wang',
source: ['/zhengce/zhengceku/:lib'],
target: (params) => `/gov/zhengce/zhengceku/${params.libs}`,
},
],
},
'xz.gov.cn': {
_name: '徐州市人民政府',
hrss: [
Expand Down
4 changes: 4 additions & 0 deletions lib/v2/gov/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ module.exports = function (router) {
router.get('/pbc/tradeAnnouncement', require('./pbc/tradeAnnouncement'));
router.get('/pbc/zcyj', require('./pbc/zcyj'));
router.get(/stats(\/[\w/-]+)?/, require('./stats'));
router.get('/zhengce/govall/:advance?', require('./zhengce/govall'));
router.get('/zhengce/wenjian/:pcodeJiguan?', require('./zhengce/wenjian'));
router.get('/zhengce/zhengceku/:department', require('./zhengce/zhengceku'));
router.get('/zhengce/zuixin', require('./zhengce/zuixin'));
// province
router.get(/anhui\/kjt\/([\w\d/-]+)?/, require('./anhui/kjt'));
router.get(/beijing\/bphc(\/[\w/-]+)?/, require('./beijing/bphc'));
Expand Down
55 changes: 55 additions & 0 deletions lib/v2/gov/zhengce/govall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const { advance } = ctx.params;
const link = `http://sousuo.gov.cn/list.htm`;
const params = new URLSearchParams({
n: 20,
t: 'govall',
sort: 'pubtime',
advance: 'true',
});
const query = `${params.toString()}&${advance}`;
const res = await got.get(link, {
searchParams: query.replace(/([\u4e00-\u9fa5])/g, (str) => encodeURIComponent(str)),
});
const $ = cheerio.load(res.data);

const list = $('body > div.dataBox > table > tbody > tr')
.slice(1)
.toArray()
.map((elem) => {
elem = $(elem);
return {
title: elem.find('td:nth-child(2) > a').text(),
link: elem.find('td:nth-child(2) > a').attr('href'),
pubDate: timezone(parseDate(elem.find('td:nth-child(5)').text()), 8),
};
});

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
let description = '';
try {
const contentData = await got(item.link);
const $ = cheerio.load(contentData.data);
description = $('#UCAP-CONTENT').html();
} catch (error) {
description = '文章已被删除';
}
item.description = description;
return item;
})
)
);

ctx.state.data = {
title: '信息稿件 - 中国政府网',
link: `${link}?${query}`,
item: items,
};
};
47 changes: 47 additions & 0 deletions lib/v2/gov/zhengce/wenjian.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const { pcodeJiguan } = ctx.params;
const link = 'http://sousuo.gov.cn/list.htm';
const res = await got(link, {
searchParams: {
n: ctx.query.limit ? Number(ctx.query.limit) : 20,
sort: 'pubtime',
t: 'paper',
pcodeJiguan: pcodeJiguan ? pcodeJiguan : '',
},
});
const $ = cheerio.load(res.data);

const list = $('body > div.dataBox > table > tbody > tr')
.slice(1)
.toArray()
.map((elem) => {
elem = $(elem);
return {
title: elem.find('td:nth-child(2) > a').text(),
link: elem.find('td:nth-child(2) > a').attr('href'),
pubDate: timezone(parseDate(elem.find('td:nth-child(5)').text()), 8),
};
});

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const contentData = await got(item.link);
const $ = cheerio.load(contentData.data);
item.description = $('#UCAP-CONTENT').html();
return item;
})
)
);

ctx.state.data = {
title: '最新文件 - 中国政府网',
link: res.url,
item: items,
};
};
22 changes: 22 additions & 0 deletions lib/v2/gov/zhengce/zhengceku.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const buildData = require('@/utils/common-config');

module.exports = async (ctx) => {
const department = ctx.params.department;
const link = `http://www.gov.cn/zhengce/zhengceku/${department}/`;

ctx.state.data = await buildData({
link,
url: link,
title: `%title%`,
description: '政府文件库, 当页的所有列表',
params: {
title: `$('.channel_tab > .noline > a').text().trim() + ' - 政府文件库'`,
},
item: {
item: '.news_box > .list > ul > li:not(.line)',
title: `$('h4 > a').text()`,
link: `$('h4 > a').attr('href')`,
pubDate: `parseDate($('h4 > .date').text().trim())`,
},
});
};
Loading