diff --git a/docs/government.md b/docs/government.md index cd7c8c495..021f9b2d1 100644 --- a/docs/government.md +++ b/docs/government.md @@ -1002,7 +1002,7 @@ pageClass: routes -## 中国政府 +## 中国政府网 ### 数据 @@ -1040,7 +1040,7 @@ pageClass: routes ### 最新文件 - + ### 信息稿件 @@ -1059,6 +1059,10 @@ pageClass: routes +### 国务院政策文件库 + + + ### 政府新闻 diff --git a/lib/router.js b/lib/router.js index 2560788af..175ff55c9 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/gov/zhengce/govall.js b/lib/routes/gov/zhengce/govall.js deleted file mode 100644 index 4c831e736..000000000 --- a/lib/routes/gov/zhengce/govall.js +++ /dev/null @@ -1,59 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -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 $list = cheerio.load(res.data); - - ctx.state.data = { - title: `信息稿件 - 中国政府网`, - link: `${link}?${query}`, - item: await Promise.all( - $list('body > div.dataBox > table > tbody > tr') - .slice(1) - .map(async (_, el) => { - const item = $list(el); - - const number = item.find('td.info').next(); - const title = item.find('td.info > a'); - const href = title.attr('href'); - - const key = `gov_zhengce: ${href}`; - let description; - const value = await ctx.cache.get(key); - - if (value) { - description = value; - } else { - try { - const contentData = await got.get(href); - const $content = cheerio.load(contentData.data); - description = $content('#UCAP-CONTENT').html(); - } catch (error) { - description = '文章已被删除'; - } - - ctx.cache.set(key, description); - } - - return { - title: number.text() + ' | ' + title.text(), - description, - link: href, - }; - }) - .get() - ), - }; -}; diff --git a/lib/routes/gov/zhengce/wenjian.js b/lib/routes/gov/zhengce/wenjian.js deleted file mode 100644 index 44e4a9a25..000000000 --- a/lib/routes/gov/zhengce/wenjian.js +++ /dev/null @@ -1,53 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const queryString = require('query-string'); - -module.exports = async (ctx) => { - const { pcodeJiguan } = ctx.params; - const link = `http://sousuo.gov.cn/list.htm`; - const res = await got.get(link, { - searchParams: queryString.stringify({ - n: 20, - sort: 'pubtime', - t: 'paper', - pcodeJiguan: pcodeJiguan ? pcodeJiguan : '', - }), - }); - const $list = cheerio.load(res.data); - - ctx.state.data = { - title: `最新文件 - 中国政府网`, - link, - item: await Promise.all( - $list('body > div.dataBox > table > tbody > tr') - .slice(1) - .map(async (_, el) => { - const item = $list(el); - - const number = item.find('td.info').next(); - const title = item.find('td.info > a'); - const href = title.attr('href'); - - const key = `gov_zhengce: ${href}`; - let description; - const value = await ctx.cache.get(key); - - if (value) { - description = value; - } else { - const contentData = await got.get(href); - const $content = cheerio.load(contentData.data); - description = $content('#UCAP-CONTENT').html(); - ctx.cache.set(key, description); - } - - return { - title: number.text() + ' | ' + title.text(), - description, - link: href, - }; - }) - .get() - ), - }; -}; diff --git a/lib/routes/gov/zhengce/zuixin.js b/lib/routes/gov/zhengce/zuixin.js deleted file mode 100644 index b027aef61..000000000 --- a/lib/routes/gov/zhengce/zuixin.js +++ /dev/null @@ -1,42 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const link = `http://www.gov.cn/zhengce/zuixin.htm`; - const listData = await got.get(link); - const $list = cheerio.load(listData.data); - ctx.state.data = { - title: `最新政策 - 中国政府网`, - link, - item: await Promise.all( - $list('.news_box .list li:not(.line)') - .map(async (_, el) => { - const $el = $list(el); - const $a = $el.find('h4 a'); - const href = $a.attr('href'); - const link = href.startsWith('/zhengce') ? `http://www.gov.cn${href}` : href; - const key = `gov_zhengce_zuixin: ${link}`; - let description; - const value = await ctx.cache.get(key); - - if (value) { - description = value; - } else { - const contentData = await got.get(link); - const $content = cheerio.load(contentData.data); - description = $content('#UCAP-CONTENT').html(); - ctx.cache.set(key, description); - } - - return { - title: $a.text(), - description, - guid: href, - link, - pubDate: new Date($el.find('.date').text()).toUTCString(), - }; - }) - .get() - ), - }; -}; diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 0e5616cd2..7d599f667 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -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'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index dba8dd5e6..cd66c71ad 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -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: [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index fdf19f16c..e6bb34fda 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -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')); diff --git a/lib/v2/gov/zhengce/govall.js b/lib/v2/gov/zhengce/govall.js new file mode 100644 index 000000000..e3042cd37 --- /dev/null +++ b/lib/v2/gov/zhengce/govall.js @@ -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, + }; +}; diff --git a/lib/v2/gov/zhengce/wenjian.js b/lib/v2/gov/zhengce/wenjian.js new file mode 100644 index 000000000..5134e53fa --- /dev/null +++ b/lib/v2/gov/zhengce/wenjian.js @@ -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, + }; +}; diff --git a/lib/v2/gov/zhengce/zhengceku.js b/lib/v2/gov/zhengce/zhengceku.js new file mode 100644 index 000000000..f74c6c033 --- /dev/null +++ b/lib/v2/gov/zhengce/zhengceku.js @@ -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())`, + }, + }); +}; diff --git a/lib/v2/gov/zhengce/zuixin.js b/lib/v2/gov/zhengce/zuixin.js new file mode 100644 index 000000000..6f0c9c793 --- /dev/null +++ b/lib/v2/gov/zhengce/zuixin.js @@ -0,0 +1,39 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const baseUrl = 'http://www.gov.cn'; + +module.exports = async (ctx) => { + const link = `${baseUrl}/zhengce/zuixin.htm`; + const listData = await got(link); + const $ = cheerio.load(listData.data); + + const list = $('.news_box .list li:not(.line)') + .toArray() + .map((elem) => { + elem = $(elem); + return { + title: elem.find('h4 a').text(), + link: new URL(elem.find('h4 a').attr('href'), baseUrl).href, + pubDate: timezone(parseDate(elem.find('h4 .date').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, + item: items, + }; +};