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(router): cebbank 光大银行 #8293

Merged
merged 3 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions docs/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,24 @@ type 为 all 时,category 参数不支持 cost 和 free

</Route>

## 光大银行

### 外汇牌价

#### 总览

<Route author="linbuxiao" example="/quotation/all" path="/quotation/all" />

#### 历史牌价

<Route author="linbuxiao" example="/quotation/history/usd" path="/quotation/history/:type" :paramsDesc="['货币的缩写,见下表']">

| 美元 | 英镑 | 港币 | 瑞士法郎 | 瑞典克郎 | 丹麦克郎 | 挪威克郎 | 日元 | 加拿大元 | 澳大利亚元 | 新加坡元 | 欧元 | 澳门元 | 泰国铢 | 新西兰元 | 韩圆 |
|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|
| usd | gbp | hkd | chf | sek | dkk | nok | jpy | cad | aud | sgd | eur | mop | thb | nzd | krw |

</Route>

## 中国邮政速递物流

### 新闻
Expand Down
48 changes: 48 additions & 0 deletions lib/v2/cebbank/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const path = require('path');
const { art } = require('@/utils/render');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const link = `https://www.cebbank.com/eportal/ui?pageId=477257`;
const content = await got({
method: 'get',
url: link,
});

const $ = cheerio.load(content.data);

const items = $('.lczj_box tbody tr')
.map((i, e) => {
if (i < 2) {
return null;
}
const c = cheerio.load(e, { decodeEntities: false });
return {
title: c('td:nth-child(1)').text(),
description: art(path.join(__dirname, 'templates/allDes.art'), {
fcer: c('td:nth-child(2)').text(),
pmc: c('td:nth-child(3)').text(),
exrt: c('td:nth-child(4)').text(),
mc: c('td:nth-child(5)').text(),
}),
};
})
.get();

ctx.state.data = {
title: '中国光大银行',
description: '中国光大银行 外汇牌价',
pubDate: timezone(parseDate($('#t_id span').text().substring(5), 'YYYY-MM-DD HH:mm', true), 0),
item: items,
};

ctx.state.json = {
title: '中国光大银行',
description: '中国光大银行 外汇牌价',
pubDate: timezone(parseDate($('#t_id span').text().substring(5), 'YYYY-MM-DD HH:mm', true), 0),
item: items,
};
};
49 changes: 49 additions & 0 deletions lib/v2/cebbank/history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const path = require('path');
const { art } = require('@/utils/render');
const utils = require('./utils');

const { TYPE } = utils;

module.exports = async (ctx) => {
const type = ctx.params.type;
const url = `https://www.cebbank.com/eportal/ui?struts.portlet.action=/portlet/whpjFront!toView.action&moduleId=12094&pageId=477260&currcode=${TYPE[type].id}&currentPagebak=1&currentPage=1`;
const res = await got({
method: 'get',
url,
});

const $ = cheerio.load(res.data);

const items = $('.lczj_box tbody tr')
.map((i, e) => {
if (i < 2) {
return null;
}
const c = cheerio.load(e, { decodeEntities: false });
return {
title: c('td:nth-child(1)').text(),
description: art(path.join(__dirname, 'templates/historyDes.art'), {
fcer: c('td:nth-child(2)').text(),
pmc: c('td:nth-child(3)').text(),
exrt: c('td:nth-child(4)').text(),
mc: c('td:nth-child(5)').text(),
time: c('td:nth-child(6)').text(),
}),
};
})
.get();
items.pop();
ctx.state.data = {
title: '中国光大银行',
description: `中国光大银行 外汇牌价 ${TYPE[type].name}`,
item: items,
};

ctx.state.json = {
title: '中国光大银行',
description: `中国光大银行 外汇牌价 ${TYPE[type].name}`,
item: items,
};
};
4 changes: 4 additions & 0 deletions lib/v2/cebbank/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/quotation/all': ['linbuxiao'],
'/quotation/history/:type': ['linbuxiao'],
};
19 changes: 19 additions & 0 deletions lib/v2/cebbank/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'cebbank.com': {
_name: '中国光大银行',
'.': [
{
title: '外汇牌价 - 牌价总览',
docs: 'https://docs.rsshub.app/new-media.html#eprice',
source: ['/eportal/ui?pageId=477257'],
target: '/quotation/all',
},
{
title: '外汇牌价 - 历史记录',
docs: 'https://docs.rsshub.app/new-media.html#eprice',
source: ['/site/ygzx/whpj/rmbwhpjlspj/index.html?currcode=:id'],
target: ({ id }) => `/quotation/${id}`,
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/cebbank/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/quotation/all', require('./all'));
router.get('/quotation/history/:type', require('./history'));
};
2 changes: 2 additions & 0 deletions lib/v2/cebbank/templates/allDes.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p>购汇:{{ fcer }},购钞:{{ pmc }}</p>
<p>结汇: {{ exrt }},结钞:{{ mc }}</p>
3 changes: 3 additions & 0 deletions lib/v2/cebbank/templates/historyDes.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>更新时间: {{ time }}</>
<p>购汇:{{ fcer }},购钞:{{ pmc }}</p>
<p>结汇: {{ exrt }},结钞:{{ mc }}</p>
70 changes: 70 additions & 0 deletions lib/v2/cebbank/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const TYPE = {
usd: {
name: '美元(USD)',
id: 14,
},
gbp: {
name: '英镑(GBP)',
id: 12,
},
hkd: {
name: '港币(HKD)',
id: 13,
},
chf: {
name: '瑞士法郎(CHF)',
id: 15,
},
sek: {
name: '瑞典克郎(SEK)',
id: 21,
},
dkk: {
name: '丹麦克郎(DKK)',
id: 22,
},
nok: {
name: '挪威克郎(NOK)',
id: 23,
},
jpy: {
name: '日元(JPY)',
id: 27,
},
cad: {
name: '加拿大元(CAD)',
id: 28,
},
aud: {
name: '澳大利亚元(AUD)',
id: 29,
},
sgd: {
name: '新加坡元(SGD)',
id: 32,
},
eur: {
name: '欧元(EUR)',
id: 38,
},
mop: {
name: '澳门元(MOP)',
id: 81,
},
thb: {
name: '泰国铢(THB)',
id: 84,
},
nzd: {
name: '新西兰元(NZD)',
id: 87,
},
krw: {
name: '韩圆(KRW)',
id: 88,
},
};

module.exports = {
TYPE,
};