Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): Add ICBC; Fix BOC Date & trimming space #13138

Merged
merged 5 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/routes/boc/whpj.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ module.exports = async (ctx) => {
.map(function () {
const zh_name = $(this).find('td:nth-child(1)').text();
const en_name = en_names[zh_name] || '';
const name = `${zh_name} ${en_name} `;
const date = `${$(this).find('td:nth-child(7)').text()} ${$(this).find('td:nth-child(8)').text()}`;
const name = `${zh_name} ${en_name}`;
const date = String($(this).find('td:nth-child(7)').text());
leoleoasd marked this conversation as resolved.
Show resolved Hide resolved

const xhmr = `现汇买入价:${$(this).find('td:nth-child(2)').text()}`;

Expand Down Expand Up @@ -77,15 +77,15 @@ module.exports = async (ctx) => {
case 'xcmc':
return `${name} ${xcmc}`;
default:
return name + content;
return `${name} ${content}`;
}
};

const info = {
title: formatTitle(),
description: content.replace(/\s/g, '<br>'),
pubDate: new Date(date).toUTCString(),
guid: name + date,
guid: `${name} ${content}`,
};
return info;
})
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/icbc/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/whpj/:format?': ['leoleoasd'],
};
13 changes: 13 additions & 0 deletions lib/v2/icbc/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'icbc.com.cn': {
_name: '中国工商银行',
'.': [
{
title: '外汇牌价',
docs: 'https://docs.rsshub.app/other#zhong-guo-gong-shang-yin-hang',
source: ['/column/1438058341489590354.html'],
target: '/icbc/whpj',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/icbc/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'));
};
57 changes: 57 additions & 0 deletions lib/v2/icbc/whpj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const got = require('@/utils/got');

module.exports = async (ctx) => {
// yes, insecure
// their openssl version isn't safe anyway (https://stackoverflow.com/questions/75763525/curl-35-error0a000152ssl-routinesunsafe-legacy-renegotiation-disabled)
const { data } = await got('http://papi.icbc.com.cn/exchanges/ns/getLatest');
const format = ctx.params.format;

ctx.state.data = {
title: '中国工商银行外汇牌价',
link: 'https://www.icbc.com.cn/column/1438058341489590354.html',
item: data.data.map((item) => {
const name = `${item.currencyCHName} ${item.currencyENName}`;

const xhmr = `现汇买入价:${item.foreignBuy}`;

const xcmr = `现钞买入价:${item.cashBuy}`;

const xhmc = `现汇卖出价:${item.foreignSell}`;

const xcmc = `现钞卖出价:${item.cashSell}`;

const zs = `参考价:${item.reference}`;

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

const formatTitle = () => {
switch (format) {
case 'short':
return name;
case 'xh':
return `${name} ${xhmr} ${xhmc}`;
case 'xc':
return `${name} ${xcmr} ${xcmc}`;
case 'zs':
return `${name} ${zs}`;
case 'xhmr':
return `${name} ${xhmr}`;
case 'xhmc':
return `${name} ${xhmc}`;
case 'xcmr':
return `${name} ${xcmr}`;
case 'xcmc':
return `${name} ${xcmc}`;
default:
return `${name} ${content}`;
}
};
return {
title: formatTitle(),
pubDate: new Date(`${item.publishDate} ${item.publishTime}`),
description: content.replace(/\s/g, '<br>'),
guid: `${name} ${item.publishDate} ${item.publishTime}`,
};
}),
};
};
Loading