From f7aecbcb9d33b2d0e45c9adf9299981fb4b33fc9 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 4 Dec 2023 15:58:50 +0000 Subject: [PATCH] feat(route): cfachina (#13949) --- lib/v2/cfachina/analygarden.js | 60 ++++++++++++++++++++++++++++++++++ lib/v2/cfachina/maintainer.js | 3 ++ lib/v2/cfachina/radar.js | 13 ++++++++ lib/v2/cfachina/router.js | 3 ++ website/docs/routes/other.mdx | 14 +++++++- 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 lib/v2/cfachina/analygarden.js create mode 100644 lib/v2/cfachina/maintainer.js create mode 100644 lib/v2/cfachina/radar.js create mode 100644 lib/v2/cfachina/router.js diff --git a/lib/v2/cfachina/analygarden.js b/lib/v2/cfachina/analygarden.js new file mode 100644 index 000000000..14f42b8d4 --- /dev/null +++ b/lib/v2/cfachina/analygarden.js @@ -0,0 +1,60 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + let { program = '分析师园地' } = ctx.params; + const baseUrl = 'https://www.cfachina.org'; + let pageData, + pageUrl = `${baseUrl}/servicesupport/analygarden/`; + + if (program !== '分析师园地') { + pageUrl = `${pageUrl}${program}/`; + + const response = await got(pageUrl); + const $ = cheerio.load(response.data); + program = $('script:contains("Paging")') + .text() + .match(/var name = '(.+)';/)[1]; + pageData = { + category: $('.crumb a') + .toArray() + .map((item) => $(item).text()) + .slice(-2), + }; + } + + const { data: response } = await got(`${baseUrl}/qx-search/api/wcmSearch/getDataByProgram`, { + headers: { + accept: 'application/json, text/plain, */*', + }, + searchParams: { + pageNo: 1, + pageSize: ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20, + keyword: '', + startTime: '', + endTime: '', + type: '', + programName: program, + }, + }); + + const items = response.data.dataList.map((item) => { + const link = new URL(item.docPubUrl, baseUrl).href; + return { + title: item.docTitle, + author: item.docAuthor, + link, + pubDate: timezone(parseDate(item.operTime), +8), + enclosure_url: link, + enclosure_type: `application/${link.split('.').pop()}`, + }; + }); + + ctx.state.data = { + title: `${pageData?.category.toReversed().join(' - ') ?? '分析师园地'} - 中国期货业协会`, + link: pageUrl, + item: items, + }; +}; diff --git a/lib/v2/cfachina/maintainer.js b/lib/v2/cfachina/maintainer.js new file mode 100644 index 000000000..f39bd98b4 --- /dev/null +++ b/lib/v2/cfachina/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/servicesupport/analygarden/:program?': ['TonyRL'], +}; diff --git a/lib/v2/cfachina/radar.js b/lib/v2/cfachina/radar.js new file mode 100644 index 000000000..6ab6ef728 --- /dev/null +++ b/lib/v2/cfachina/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'cfachina.org': { + _name: '中国期货业协会', + '.': [ + { + title: '分析师园地', + docs: 'https://docs.rsshub.app/other#zhong-guo-qi-huo-ye-xie-hui', + source: ['/servicesupport/analygarden/:program?', '/'], + target: '/cfachina/servicesupport/analygarden/:program?', + }, + ], + }, +}; diff --git a/lib/v2/cfachina/router.js b/lib/v2/cfachina/router.js new file mode 100644 index 000000000..2f4c4bf55 --- /dev/null +++ b/lib/v2/cfachina/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/servicesupport/analygarden/:program?', require('./analygarden')); +}; diff --git a/website/docs/routes/other.mdx b/website/docs/routes/other.mdx index d0f3e410a..031dcd669 100644 --- a/website/docs/routes/other.mdx +++ b/website/docs/routes/other.mdx @@ -1318,6 +1318,19 @@ Refer to [the list of supported currencies](https://wise.com/tools/exchange-rate +## 中国期货业协会 {#zhong-guo-qi-huo-ye-xie-hui} + +### 分析师园地 {#zhong-guo-qi-huo-ye-xie-hui-fen-xi-shi-yuan-di} + + + +| 有色金属类 | 黑色金属类 | 能源化工类 | 贵金属类 | 农产品类 | 金融类 | 指数类 | +| --------- | -------- | -------- | ------- | ------- | ----- | ----- | +| ysjsl | hsjsl | nyhgl | gjjsl | ncpl | jrl | zsl | + + + + ## 中国银行 {#zhong-guo-yin-hang} ### 外汇牌价 {#zhong-guo-yin-hang-wai-hui-pai-jia} @@ -1357,4 +1370,3 @@ Refer to [the list of supported currencies](https://wise.com/tools/exchange-rate ### はてな匿名ダイアリー - 人気記事アーカイブ {#%E3%81%AF%E3%81%A6%E3%81%AA-%E3%81%AF%E3%81%A6%E3%81%AA-ni-ming-%E3%83%80%E3%82%A4%E3%82%A2%E3%83%AA%E3%83%BC-ren-qi-ji-shi-%E3%82%A2%E3%83%BC%E3%82%AB%E3%82%A4%E3%83%96} -