From a4ce5128abb6b263039b729d0cf7be3590046f88 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Sun, 15 May 2022 22:21:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=B2=B3=E5=8C=97?= =?UTF-8?q?=E7=9C=81=E8=B4=A2=E6=94=BF=E5=8E=85=20(#9759)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 河北省财政厅 * regenerate * fix typo * fix typo --- docs/government.md | 10 ++++++++ lib/v2/gov/hebei/czt.js | 53 ++++++++++++++++++++++++++++++++++++++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/radar.js | 35 ++++++++++++++++++++++++++ lib/v2/gov/router.js | 1 + 5 files changed, 100 insertions(+) create mode 100644 lib/v2/gov/hebei/czt.js diff --git a/docs/government.md b/docs/government.md index 8c104b2bd4..963baa9b66 100644 --- a/docs/government.md +++ b/docs/government.md @@ -725,6 +725,16 @@ pageClass: routes +### 河北省财政厅 + + + +| 财政动态 | 综合新闻 | 通知公告 | +| ---- | ---- | ---- | +| gzdt | zhxw | tzgg | + + + ### 河北省退役军人事务厅 diff --git a/lib/v2/gov/hebei/czt.js b/lib/v2/gov/hebei/czt.js new file mode 100644 index 0000000000..d5603de565 --- /dev/null +++ b/lib/v2/gov/hebei/czt.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'gzdt'; + + const rootUrl = 'http://czt.hebei.gov.cn'; + const currentUrl = `${rootUrl}/xwdt/${category}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('td li a[title]') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}${/^\.\.\/\.\./.test(item.attr('href')) ? item.attr('href').replace(/^\.\.\/\.\./, '') : `/xwdt/${category}${item.attr('href').replace(/^\./, '')}`}`, + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.author = content('meta[name="ContentSource"]').attr('content'); + item.pubDate = parseDate(content('meta[name="PubDate"]').attr('content')); + item.description = content('.TRS_Editor, .content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 00ff01a1d9..7645d58fc4 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -17,6 +17,7 @@ module.exports = { '/anhui/kjt/:path?': ['nczitzk'], '/beijing/kw/:channel': ['Fatpandac'], + '/hebei/czt/xwdt/:category?': ['nczitzk'], '/shenzhen/hrss/szksy/:caty/:page?': ['zlasd'], '/shenzhen/zzb/:caty/:page?': ['zlasd'], '/shanghai/rsj/ksxm': ['Fatpandac'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index 116cf0090f..9bbbb47ff3 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -300,6 +300,41 @@ module.exports = { }, ], }, + 'hebei.gov.cn': { + _name: '河北省人民政府', + czt: [ + { + title: '河北省财政厅 - 财政动态', + docs: 'https://docs.rsshub.app/government.html#he-bei-sheng-cai-zheng-ting-cai-zheng-dong-tai', + source: ['/xwdt/:category'], + target: (params) => { + if (params.category === 'gzdt') { + return '/gov/hebei/czt/xwdt/:category'; + } + }, + }, + { + title: '河北省财政厅 - 综合新闻', + docs: 'https://docs.rsshub.app/government.html#he-bei-sheng-cai-zheng-ting-zong-he-xin-wen', + source: ['/xwdt/:category'], + target: (params) => { + if (params.category === 'zhxw') { + return '/gov/hebei/czt/xwdt/:category'; + } + }, + }, + { + title: '河北省财政厅 - 通知公告', + docs: 'https://docs.rsshub.app/government.html#he-bei-sheng-cai-zheng-ting-tong-zhi-gong-gao', + source: ['/xwdt/:category'], + target: (params) => { + if (params.category === 'tzgg') { + return '/gov/hebei/czt/xwdt/:category'; + } + }, + }, + ], + }, 'homeaffairs.gov.au': { _name: 'Department of Home Affairs', immi: [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index e285591b04..853d6c35f8 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -18,6 +18,7 @@ module.exports = function (router) { // province router.get(/anhui\/kjt\/([\w\d/-]+)?/, require('./anhui/kjt')); router.get('/beijing/kw/:channel', require('./beijing/kw/index')); + router.get('/hebei/czt/xwdt/:category?', require('./hebei/czt')); router.get('/shenzhen/hrss/szksy/:caty/:page?', require('./shenzhen/hrss/szksy/index')); router.get('/shenzhen/zzb/:caty/:page?', require('./shenzhen/zzb/index')); router.get('/shanghai/rsj/ksxm', require('./shanghai/rsj/ksxm'));