From 80aab00fdb199ab1d6b0b86db65811efbc224bd9 Mon Sep 17 00:00:00 2001 From: yuxinliu-alex Date: Tue, 19 Apr 2022 19:51:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E5=9B=BD=E5=AE=B6=E5=B9=BF?= =?UTF-8?q?=E6=92=AD=E7=94=B5=E8=A7=86=E6=80=BB=E5=B1=80=20(#9566)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 国家广播电视总局 * move the nrta to lib\v2\gov * fix: feed link * fix: radar * fix: radar Co-authored-by: alex --- docs/government.md | 11 +++++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/nrta/news.js | 63 ++++++++++++++++++++++++++++++++++++++++ lib/v2/gov/radar.js | 11 +++++++ lib/v2/gov/router.js | 1 + 5 files changed, 87 insertions(+) create mode 100644 lib/v2/gov/nrta/news.js diff --git a/docs/government.md b/docs/government.md index 07cb278c7f..4d4a02ef75 100644 --- a/docs/government.md +++ b/docs/government.md @@ -156,6 +156,17 @@ pageClass: routes +## 国家广播电视总局 + +### 分类 + + + +| 总局要闻 | 公告公示 | 工作动态 | 其他 | +|:----:|:----:|:----:|:----:| +| 112 | 113 | 114 | + + ## 国家税务总局 ### 最新文件 diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index d74140d0d4..c17a955792 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -16,6 +16,7 @@ module.exports = { '/miit/wjgs': ['Yoge-Code'], '/miit/zcjd': ['Yoge-Code'], '/mee/ywdt?': ['liuxsdev'], + '/nrta/news/:category?': ['yuxinliu-alex'], '/pbc/goutongjiaoliu': ['nczitzk'], '/pbc/tradeAnnouncement': ['nczitzk'], '/pbc/zcyj': ['Fatpandac'], diff --git a/lib/v2/gov/nrta/news.js b/lib/v2/gov/nrta/news.js new file mode 100644 index 0000000000..3ee0dc196c --- /dev/null +++ b/lib/v2/gov/nrta/news.js @@ -0,0 +1,63 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const categories = { + 112: '总局要闻', + 113: '公告公示', + 114: '工作动态', +}; + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 112; + + const rootUrl = 'http://www.nrta.gov.cn'; + + const currentUrl = `${rootUrl}/col/col${category}/index.html`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const regex = /(?=\s*<)/gi; + const data = response.data.replace(regex, '$1'); + + const $ = cheerio.load(data, { + normalizeWhitespace: true, + xmlMode: true, + }); + + const list = $('a', 'record') + .map((_, item) => { + item = $(item); + return { + link: item.attr('href'), + }; + }) + .get(); + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + item.title = content('td[id="artTitMob"]').text(); + item.description = content('div[id="c"]').html(); + item.pubDate = timezone(parseDate(content('.mobile_time.shareWarpTime').text().trim()), +8); + item.author = content('.mobile_time.shareFromz').text(); + return item; + }) + ) + ); + ctx.state.data = { + title: category in categories ? categories[category] : '其他', + link: `http://www.nrta.gov.cn/col/col${category}/index.html`, + description: '国家广播电视总局', + language: 'zh-cn', + item: items, + }; +}; diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index 89a973afed..f78969e7e8 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -374,6 +374,17 @@ module.exports = { }, ], }, + 'nrta.gov.cn': { + _name: '国家广播电视总局', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/government.html#nrta-gov', + source: ['/col/*category'], + target: (params) => `/gov/nrta/news/${params.category.replace('col', '').replace('/index.html', '')}`, + }, + ], + }, 'pbc.gov.cn': { _name: '中国人民银行', '.': [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index e539b2030f..6dd0d04f5c 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -17,6 +17,7 @@ module.exports = function (router) { router.get('/miit/wjgs', require('./miit/wjgs')); router.get('/miit/zcjd', require('./miit/zcjd')); router.get('/mee/ywdt/:category?', require('./mee/ywdt')); + router.get('/nrta/news/:category?', require('./nrta/news')); router.get('/pbc/goutongjiaoliu', require('./pbc/goutongjiaoliu')); router.get('/pbc/tradeAnnouncement', require('./pbc/tradeAnnouncement')); router.get('/pbc/gzlw', require('./pbc/gzlw'));