Skip to content

Commit

Permalink
feat(route): cib/whpj (DIYgod#14539)
Browse files Browse the repository at this point in the history
* feat(route): cib/whpj

兴业银行外汇牌价

* fix lint & security issue

* fix code review
  • Loading branch information
Qixingchen authored Feb 23, 2024
1 parent a0f571f commit 774f8c9
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/v2/boc/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
'.': [
{
title: '外汇牌价',
docs: 'https://docs.rsshub.app/routes/others#zhong-guo-yin-hang',
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-yin-hang',
source: ['/sourcedb/whpj', '/'],
target: '/boc/whpj',
},
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/cib/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/whpj/:format?': ['Qixingchen'],
};
13 changes: 13 additions & 0 deletions lib/v2/cib/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'cib.com.cn': {
_name: '中国兴业银行',
'.': [
{
title: '外汇牌价',
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-xing-ye-yin-hang',
source: ['/'],
target: '/cib/whpj',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/cib/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/whpj/:format?', require('./whpj'));
};
85 changes: 85 additions & 0 deletions lib/v2/cib/whpj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const https = require('https');
const crypto = require('crypto');
const config = require('@/config').value;

module.exports = async (ctx) => {
// fix unsafe legacy renegotiation disabled
const agent = new https.Agent({
secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT,
});

const response = await got('https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery.do', { agent: { https: agent } });
const cookies = response.headers['set-cookie'].map((item) => item.split(';')[0]).join(';');

const $ = cheerio.load(response.data);
let date = $('div.main-body').find('div.labe_text').text();
date = date.split('\n\t')[1].replace('日期:', '').trim();
date = date.substring(0, 11) + date.substring(15);

const link = 'https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery/list?_search=false&dataSet.rows=80&dataSet.page=1&dataSet.sidx=&dataSet.sord=asc';
const data = await ctx.cache.tryGet(
link,
async () => {
const detailResponse = await got(link, {
headers: {
Cookie: cookies,
},
agent: { https: agent },
});
return detailResponse.data;
},
config.cache.contentExpire,
false
);

const format = ctx.params.format;

ctx.state.data = {
title: '中国兴业银行外汇牌价',
link: 'https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery.do',
item: data.rows.map((item) => {
const name = `${item.cell[0]} ${item.cell[1]}`;

const xhmr = `现汇买入价:${item.cell[3]}`;

const xcmr = `现钞买入价:${item.cell[5]}`;

const xhmc = `现汇卖出价:${item.cell[4]}`;

const xcmc = `现钞卖出价:${item.cell[6]}`;

const content = `${xhmr} ${xcmr} ${xhmc} ${xcmc}`;

return {
title: formatTitle(name, xhmr, xcmr, xhmc, xcmc, content, format),
pubDate: parseDate(date, 'YYYY年MM月DD日 HH:mm:ss'),
description: content.replaceAll(/\s/g, '<br>'),
guid: `${item.cell[0]} ${item.cell[1]} ${date}`,
};
}),
};
};

function formatTitle(name, xhmr, xcmr, xhmc, xcmc, content, format) {
switch (format) {
case 'short':
return name;
case 'xh':
return `${name} ${xhmr} ${xhmc}`;
case 'xc':
return `${name} ${xcmr} ${xcmc}`;
case 'xhmr':
return `${name} ${xhmr}`;
case 'xhmc':
return `${name} ${xhmc}`;
case 'xcmr':
return `${name} ${xcmr}`;
case 'xcmc':
return `${name} ${xcmc}`;
default:
return `${name} ${content}`;
}
}
2 changes: 1 addition & 1 deletion lib/v2/iqnew/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
'.': [
{
title: '最近更新',
docs: 'https://docs.rsshub.app/routes/others#ai-q-sheng-huo-wang',
docs: 'https://docs.rsshub.app/routes/other#ai-q-sheng-huo-wang',
source: ['/post/new_100/', '/'],
target: '/iqnew/latest',
},
Expand Down
10 changes: 10 additions & 0 deletions website/docs/routes/other.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,16 @@ Specify options (in the format of query string) in parameter `routeParams` param
| xxkd | gzdt | ztfx |
</Route>

## 中国兴业银行 {#zhong-guo-xing-ye-yin-hang}

### 外汇牌价 {#zhong-guo-xing-ye-yin-hang-wai-hui-pai-jia}

<Route author="Qixingchen" example="/cib/whpj/xh?filter_title=USD" path="/cib/whpj/:format?" paramsDesc={['输出的标题格式,默认为标题 + 所有价格。短格式仅包含货币名称。']}>
| 短格式 | 现汇买卖 | 现钞买卖 | 现汇买入 | 现汇卖出 | 现钞买入 | 现钞卖出 |
| ------ | -------- | -------- | -------- | -------- | -------- | -------- |
| short | xh | xc | xhmr | xhmc | xcmr | xcmc |
</Route>

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

### 外汇牌价 {#zhong-guo-yin-hang-wai-hui-pai-jia}
Expand Down

0 comments on commit 774f8c9

Please sign in to comment.