From d3a5949402f2f4e3a91bf8cb0cb8eac6d28ac029 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Tue, 5 Jul 2022 19:40:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E9=99=95=E8=A5=BF?= =?UTF-8?q?=E7=9C=81=E7=A7=91=E5=AD=A6=E6=8A=80=E6=9C=AF=E5=8E=85=20(#1011?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 陕西省科学技术厅 * fix typo * fix: pubDate * fix typo --- docs/government.md | 12 +++++++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/radar.js | 11 ++++++++ lib/v2/gov/router.js | 1 + lib/v2/gov/shaanxi/kjt.js | 55 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 lib/v2/gov/shaanxi/kjt.js diff --git a/docs/government.md b/docs/government.md index 9bbbc8b6e..9f777df63 100644 --- a/docs/government.md +++ b/docs/government.md @@ -366,6 +366,18 @@ pageClass: routes +## 陕西省人民政府 + +### 陕西省科学技术厅 + + + +| 科技头条 | 工作动态 | 基层科技 | 科技博览 | 媒体聚焦 | 通知公告 | +| ---- | ---- | ---- | ---- | ---- | ---- | +| 1061 | 24 | 27 | 25 | 28 | 221 | + + + ## 上海市人民政府 ### 上海市职业能力考试院 考试项目 diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index e99eae176..6e7fcb558 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -22,6 +22,7 @@ module.exports = { '/beijing/jw/tzgg': ['nczitzk'], '/beijing/kw/:channel': ['Fatpandac'], '/hebei/czt/xwdt/:category?': ['nczitzk'], + '/shaanxi/kjt/:id?': ['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 3e46d658b..db9f6f07f 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -520,6 +520,17 @@ module.exports = { }, ], }, + 'shaanxi.gov.cn': { + _name: '陕西省人民政府', + kjt: [ + { + title: '陕西省科学技术厅', + docs: 'https://docs.rsshub.app/government.html#shan-xi-ren-min-zheng-fu-shan-xi-sheng-ke-xue-ji-shu-ting', + source: ['/view/iList.jsp', '/'], + target: (params, url) => `/gov/shaanxi/kjt/${new URL(url).searchParams.get('cat_id')}`, + }, + ], + }, 'sz.gov.cn': { _name: '深圳政府在线移动门户', hrss: [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index e0cb3936a..609bd615a 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -22,6 +22,7 @@ module.exports = function (router) { router.get('/beijing/jw/tzgg', require('./beijing/jw/tzgg')); router.get('/beijing/kw/:channel', require('./beijing/kw/index')); router.get('/hebei/czt/xwdt/:category?', require('./hebei/czt')); + router.get('/shaanxi/kjt/:id?', require('./shaanxi/kjt')); 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')); diff --git a/lib/v2/gov/shaanxi/kjt.js b/lib/v2/gov/shaanxi/kjt.js new file mode 100644 index 000000000..9a057364c --- /dev/null +++ b/lib/v2/gov/shaanxi/kjt.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const id = ctx.params.id ?? '221'; + + const rootUrl = 'https://kjt.shaanxi.gov.cn'; + const currentUrl = `${rootUrl}/view/iList.jsp?cat_id=${id}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.textlist li a') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + pubDate: parseDate(item.prev().text()), + }; + }); + + 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.description = content('.info_content').html(); + item.author = content('meta[name="Author"]').attr('content'); + item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').attr('content')), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `陕西省科学技术厅 - ${$('.catnm').text()}`, + link: currentUrl, + item: items, + }; +};