From fd40d038414dd455c15c08a24ff5aad6880fbde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A0=E9=99=A5=E9=9B=BB=E6=B0=97?= Date: Sun, 5 Feb 2023 21:23:11 +0800 Subject: [PATCH] feat(route): add crac (#11776) * feat(route): add crac * fixup --- docs/government.md | 12 ++++++++++ lib/v2/crac/index.js | 46 +++++++++++++++++++++++++++++++++++++++ lib/v2/crac/maintainer.js | 3 +++ lib/v2/crac/radar.js | 13 +++++++++++ lib/v2/crac/router.js | 3 +++ 5 files changed, 77 insertions(+) create mode 100644 lib/v2/crac/index.js create mode 100644 lib/v2/crac/maintainer.js create mode 100644 lib/v2/crac/radar.js create mode 100644 lib/v2/crac/router.js diff --git a/docs/government.md b/docs/government.md index 0ae0e8acaf..aa7d48a88f 100644 --- a/docs/government.md +++ b/docs/government.md @@ -1066,6 +1066,18 @@ pageClass: routes +## 中国无线电协会业余无线电分会 + +### 最新资讯 + + + +| 新闻动态 | 通知公告 | 政策法规 | 常见问题 | 资料下载 | English | 业余中继台 | 科普专栏 | +| ---- | ---- | ---- | ---- | ---- | ------- | ----- | ---- | +| 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | + + + ## 中国信息通信研究院 ### 白皮书 diff --git a/lib/v2/crac/index.js b/lib/v2/crac/index.js new file mode 100644 index 0000000000..34a93694f1 --- /dev/null +++ b/lib/v2/crac/index.js @@ -0,0 +1,46 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const baseUrl = 'http://www.crac.org.cn'; + const type = ctx.params.type; + const link = type ? `${baseUrl}/News/List?type=${type}` : `${baseUrl}/News/List`; + + const response = await got({ + method: 'get', + url: link, + }); + + const $ = cheerio.load(response.data); + const list = $('div.InCont_r_d_cont > li') + .map((_, item) => { + item = $(item); + return { + link: new URL(item.find('a').attr('href'), baseUrl).href, + pubDate: parseDate(item.find('span.cont_d').text(), 'YYYY-MM-DD'), + }; + }) + .get(); + + await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(response.data); + item.title = content('div.r_d_cont_title > h3').text(); + item.description = content('div.r_d_cont').html().trim().replace(/\n/g, ''); + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link, + item: list, + }; +}; diff --git a/lib/v2/crac/maintainer.js b/lib/v2/crac/maintainer.js new file mode 100644 index 0000000000..2e9657170f --- /dev/null +++ b/lib/v2/crac/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:type?': ['Misaka13514'], +}; diff --git a/lib/v2/crac/radar.js b/lib/v2/crac/radar.js new file mode 100644 index 0000000000..8576fa5cef --- /dev/null +++ b/lib/v2/crac/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'crac.org.cn': { + _name: '中国无线电协会业余无线电分会', + www: [ + { + title: '最新资讯', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-wu-xian-dian-xie-hui-ye-yu-wu-xian-dian-fen-hui', + source: '/News/List', + target: (params, url) => `/crac/${new URL(url).searchParams.get('type') || ''}`, + }, + ], + }, +}; diff --git a/lib/v2/crac/router.js b/lib/v2/crac/router.js new file mode 100644 index 0000000000..7ec1cc98e8 --- /dev/null +++ b/lib/v2/crac/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:type?', require('./index')); +};