Skip to content

Commit

Permalink
feat(route): Add ICBC; Fix BOC Date & trimming space (#13138)
Browse files Browse the repository at this point in the history
* Add ICBC; Fix BOC Date & trimming space

* use http instead of https

* Update website/docs/routes/other.md

* Update lib/routes/boc/whpj.js

* refactor: migrate to v2

---------
  • Loading branch information
leoleoasd authored Aug 30, 2023
1 parent d5b1beb commit 05bb835
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 77 deletions.
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ router.get('/paidai/bbs', lazyloadRouteHandler('./routes/paidai/bbs'));
router.get('/paidai/news', lazyloadRouteHandler('./routes/paidai/news'));

// 中国银行
router.get('/boc/whpj/:format?', lazyloadRouteHandler('./routes/boc/whpj'));
// router.get('/boc/whpj/:format?', lazyloadRouteHandler('./routes/boc/whpj'));

// 漫画db
router.get('/manhuadb/comics/:id', lazyloadRouteHandler('./routes/manhuadb/comics'));
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/boc/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/whpj/:format?': ['LogicJake', 'HenryQW'],
};
13 changes: 13 additions & 0 deletions lib/v2/boc/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'boc.cn': {
_name: '中国银行',
'.': [
{
title: '外汇牌价',
docs: 'https://docs.rsshub.app/routes/others#zhong-guo-yin-hang',
source: ['/sourcedb/whpj', '/'],
target: '/boc/whpj',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/boc/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'));
};
16 changes: 8 additions & 8 deletions lib/routes/boc/whpj.js → lib/v2/boc/whpj.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const link = 'http://www.boc.cn/sourcedb/whpj/';
const response = await got.get(link);
const link = 'https://www.boc.cn/sourcedb/whpj/';
const response = await got(link);
const $ = cheerio.load(response.data);

const format = ctx.params.format;
Expand Down Expand Up @@ -40,11 +40,12 @@ module.exports = async (ctx) => {

const out = $('div.publish table tbody tr')
.slice(2)
.toArray()
.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 = $(this).find('td:nth-child(7)').text();

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

Expand Down Expand Up @@ -77,19 +78,18 @@ 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;
})
.get();
});

ctx.state.data = {
title: '中国银行外汇牌价',
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

0 comments on commit 05bb835

Please sign in to comment.