From 808859d4b284ce9a127a0e23a4f1f24d83ebde77 Mon Sep 17 00:00:00 2001 From: zeng Date: Sun, 20 Nov 2022 02:06:45 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(route):=20add=20=E5=9B=BD=E5=8A=A1?= =?UTF-8?q?=E9=99=A2=E6=94=BF=E7=AD=96=E6=96=87=E4=BB=B6=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/government.md | 4 ++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/radar.js | 11 +++++++++++ lib/v2/gov/router.js | 1 + lib/v2/gov/zhengceku/index.js | 22 ++++++++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 lib/v2/gov/zhengceku/index.js diff --git a/docs/government.md b/docs/government.md index cd7c8c49581b15..d7b765aa2b66f2 100644 --- a/docs/government.md +++ b/docs/government.md @@ -1350,3 +1350,7 @@ pageClass: routes ::: + +## 国务院政策文件库 + + diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 0e5616cd2e305b..81d3c1606a4af2 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -35,6 +35,7 @@ module.exports = { '/pbc/tradeAnnouncement': ['nczitzk'], '/pbc/zcyj': ['Fatpandac'], '/stats/:path+': ['bigfei'], + '/zhengceku/:department': ['zxx457'], // province '/anhui/kjt/:path?': ['nczitzk'], '/beijing/bphc/:channel': ['bigfei'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index dba8dd5e6ce971..a58e18a95355b3 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -787,4 +787,15 @@ module.exports = { }, ], }, + 'gov.cn': { + _name: '国务院部门文件', + www: [ + { + title: '国务院部门文件', + docs: 'https://docs.rsshub.app/government.html#guo-wu-yuan-bu-men-wen-jian', + source: ['/zhengce/zhengceku/:lib/*'], + target: (params) => `/gov/zhengceku/${params.libs}`, + }, + ], + }, }; diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index fdf19f16c5cac4..9dec8869601677 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -27,6 +27,7 @@ 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('/zhengceku/:department', require('./zhengceku')); // province router.get(/anhui\/kjt\/([\w\d/-]+)?/, require('./anhui/kjt')); router.get(/beijing\/bphc(\/[\w/-]+)?/, require('./beijing/bphc')); diff --git a/lib/v2/gov/zhengceku/index.js b/lib/v2/gov/zhengceku/index.js new file mode 100644 index 00000000000000..f74c6c033e3360 --- /dev/null +++ b/lib/v2/gov/zhengceku/index.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())`, + }, + }); +}; From d370874a9ac7d4149661c7f9c686fdd519c0ba45 Mon Sep 17 00:00:00 2001 From: zeng Date: Sun, 20 Nov 2022 02:21:47 +0800 Subject: [PATCH 2/4] fix wrong author --- docs/government.md | 2 +- lib/v2/gov/maintainer.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/government.md b/docs/government.md index d7b765aa2b66f2..2fe9e183be050a 100644 --- a/docs/government.md +++ b/docs/government.md @@ -1353,4 +1353,4 @@ pageClass: routes ## 国务院政策文件库 - + diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 81d3c1606a4af2..eab0349c978997 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -35,7 +35,7 @@ module.exports = { '/pbc/tradeAnnouncement': ['nczitzk'], '/pbc/zcyj': ['Fatpandac'], '/stats/:path+': ['bigfei'], - '/zhengceku/:department': ['zxx457'], + '/zhengceku/:department': ['zxx-457'], // province '/anhui/kjt/:path?': ['nczitzk'], '/beijing/bphc/:channel': ['bigfei'], From c1621e57031eac972d6e3b49f7a4be7cb15918f5 Mon Sep 17 00:00:00 2001 From: zeng Date: Sun, 20 Nov 2022 10:26:50 +0800 Subject: [PATCH 3/4] typo --- lib/v2/gov/radar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index a58e18a95355b3..6df5c33f91d08b 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -792,7 +792,7 @@ module.exports = { www: [ { title: '国务院部门文件', - docs: 'https://docs.rsshub.app/government.html#guo-wu-yuan-bu-men-wen-jian', + docs: 'https://docs.rsshub.app/government.html#guo-wu-yuan-zheng-ze-wen-jian-ku', source: ['/zhengce/zhengceku/:lib/*'], target: (params) => `/gov/zhengceku/${params.libs}`, }, From 138cdc3737b7633cf937acd6378921ba4d7b6015 Mon Sep 17 00:00:00 2001 From: TonyRL Date: Mon, 21 Nov 2022 17:44:47 +0000 Subject: [PATCH 4/4] refactor: migrate to v2 --- docs/government.md | 12 ++-- lib/router.js | 6 +- lib/routes/gov/zhengce/govall.js | 59 ------------------- lib/routes/gov/zhengce/wenjian.js | 53 ----------------- lib/routes/gov/zhengce/zuixin.js | 42 ------------- lib/v2/gov/maintainer.js | 5 +- lib/v2/gov/radar.js | 40 +++++++++---- lib/v2/gov/router.js | 5 +- lib/v2/gov/zhengce/govall.js | 55 +++++++++++++++++ lib/v2/gov/zhengce/wenjian.js | 47 +++++++++++++++ .../index.js => zhengce/zhengceku.js} | 0 lib/v2/gov/zhengce/zuixin.js | 39 ++++++++++++ 12 files changed, 187 insertions(+), 176 deletions(-) delete mode 100644 lib/routes/gov/zhengce/govall.js delete mode 100644 lib/routes/gov/zhengce/wenjian.js delete mode 100644 lib/routes/gov/zhengce/zuixin.js create mode 100644 lib/v2/gov/zhengce/govall.js create mode 100644 lib/v2/gov/zhengce/wenjian.js rename lib/v2/gov/{zhengceku/index.js => zhengce/zhengceku.js} (100%) create mode 100644 lib/v2/gov/zhengce/zuixin.js diff --git a/docs/government.md b/docs/government.md index 2fe9e183be050a..021f9b2d13cb24 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 +### 国务院政策文件库 + + + ### 政府新闻 @@ -1350,7 +1354,3 @@ pageClass: routes ::: - -## 国务院政策文件库 - - diff --git a/lib/router.js b/lib/router.js index 2560788af471ab..175ff55c9d13d2 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 4c831e7366e358..00000000000000 --- 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 44e4a9a25cab10..00000000000000 --- 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 b027aef612b5d4..00000000000000 --- 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 eab0349c978997..7d599f667646e9 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -35,7 +35,10 @@ module.exports = { '/pbc/tradeAnnouncement': ['nczitzk'], '/pbc/zcyj': ['Fatpandac'], '/stats/:path+': ['bigfei'], - '/zhengceku/:department': ['zxx-457'], + '/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 6df5c33f91d08b..cd66c71adc98a2 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: [ @@ -787,15 +816,4 @@ module.exports = { }, ], }, - 'gov.cn': { - _name: '国务院部门文件', - www: [ - { - title: '国务院部门文件', - docs: 'https://docs.rsshub.app/government.html#guo-wu-yuan-zheng-ze-wen-jian-ku', - source: ['/zhengce/zhengceku/:lib/*'], - target: (params) => `/gov/zhengceku/${params.libs}`, - }, - ], - }, }; diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 9dec8869601677..e6bb34fda43d60 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -27,7 +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('/zhengceku/:department', require('./zhengceku')); + 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 00000000000000..e3042cd379fdd7 --- /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 00000000000000..5134e53fa16c37 --- /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/zhengceku/index.js b/lib/v2/gov/zhengce/zhengceku.js similarity index 100% rename from lib/v2/gov/zhengceku/index.js rename to lib/v2/gov/zhengce/zhengceku.js diff --git a/lib/v2/gov/zhengce/zuixin.js b/lib/v2/gov/zhengce/zuixin.js new file mode 100644 index 00000000000000..6f0c9c79374a55 --- /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, + }; +};