Skip to content

Commit

Permalink
feat(route): cfachina (#13949)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL committed Dec 4, 2023
1 parent 3f00c0f commit f7aecbc
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
60 changes: 60 additions & 0 deletions lib/v2/cfachina/analygarden.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
3 changes: 3 additions & 0 deletions lib/v2/cfachina/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/servicesupport/analygarden/:program?': ['TonyRL'],
};
13 changes: 13 additions & 0 deletions lib/v2/cfachina/radar.js
Original file line number Diff line number Diff line change
@@ -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?',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/cfachina/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/servicesupport/analygarden/:program?', require('./analygarden'));
};
14 changes: 13 additions & 1 deletion website/docs/routes/other.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,19 @@ Refer to [the list of supported currencies](https://wise.com/tools/exchange-rate

<Route author="Fatpandac" example="/piyao/jrpy" path="/piyao/jrpy"/>

## 中国期货业协会 {#zhong-guo-qi-huo-ye-xie-hui}

### 分析师园地 {#zhong-guo-qi-huo-ye-xie-hui-fen-xi-shi-yuan-di}

<Route author="TonyRL" example="/cfachina/servicesupport/analygarden" path="/cfachina/servicesupport/analygarden/:program?" paramsDesc={['分类,见下表,留空为全部']} radar="1">

| 有色金属类 | 黑色金属类 | 能源化工类 | 贵金属类 | 农产品类 | 金融类 | 指数类 |
| --------- | -------- | -------- | ------- | ------- | ----- | ----- |
| ysjsl | hsjsl | nyhgl | gjjsl | ncpl | jrl | zsl |

</Route>


## 中国银行 {#zhong-guo-yin-hang}

### 外汇牌价 {#zhong-guo-yin-hang-wai-hui-pai-jia}
Expand Down Expand Up @@ -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}

<Route author="masakichi" example="/hatena/anonymous_diary/archive" path="/hatena/anonymous_diary/archive"/>

0 comments on commit f7aecbc

Please sign in to comment.