feat: 中国银行外汇牌价 多格式标题支持 (#2152)

This commit is contained in:
Henry Wang
2019-05-17 03:51:49 +01:00
committed by DIYgod
parent 2e9b312e69
commit b3c93b8ba8
3 changed files with 52 additions and 10 deletions

View File

@@ -791,8 +791,7 @@ type 为 all 时category 参数不支持 cost 和 free
### 首页
<Route author="kimi360" example="/iplay/home" path="/iplay/home">
</Route>
<Route author="kimi360" example="/iplay/home" path="/iplay/home"/>
## 移动支付网
@@ -816,7 +815,13 @@ type 为 all 时category 参数不支持 cost 和 free
### 中国银行外汇牌价
<Route author="LogicJake" example="/boc/whpj" path="/boc/whpj" />
<Route author="LogicJake HenryQW" example="/boc/whpj/zs?filter_title=%E8%8B%B1%E9%95%91" path="/boc/whpj/:format?" :paramsDesc="['输出的标题格式,默认为标题 + 所有价格。短格式仅包含货币名称。']">
| 短格式 | 中行折算价 | 现汇买卖 | 现钞买卖 | 现汇买入 | 现汇卖出 | 现钞买入 | 现钞卖出 |
| ------ | ---------- | -------- | -------- | -------- | -------- | -------- | -------- |
| short | zs | xh | xc | xhmr | xhmc | xcmr | xcmc |
</Route>
## 自如

View File

@@ -1282,7 +1282,7 @@ router.get('/paidai/bbs', require('./routes/paidai/bbs'));
router.get('/paidai/news', require('./routes/paidai/news'));
// 中国银行
router.get('/boc/whpj', require('./routes/boc/whpj'));
router.get('/boc/whpj/:format?', require('./routes/boc/whpj'));
// 漫画db
router.get('/manhuadb/comics/:id', require('./routes/manhuadb/comics'));

View File

@@ -6,6 +6,8 @@ module.exports = async (ctx) => {
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const format = ctx.params.format;
const out = $('div.publish table tbody tr')
.slice(2)
.map(function() {
@@ -17,19 +19,54 @@ module.exports = async (ctx) => {
.text()} ${$(this)
.find('td:nth-child(8)')
.text()}`;
const content = `现汇买入价:${$(this)
const xhmr = `现汇买入价:${$(this)
.find('td:nth-child(2)')
.text()} 现钞买入价:${$(this)
.text()}`;
const xcmr = `现钞买入价:${$(this)
.find('td:nth-child(3)')
.text()} 现汇卖出价:${$(this)
.text()}`;
const xhmc = `现汇卖出价:${$(this)
.find('td:nth-child(4)')
.text()} 现钞卖出价:${$(this)
.text()}`;
const xcmc = `现钞卖出价:${$(this)
.find('td:nth-child(5)')
.text()} 中行折算价:${$(this)
.text()}`;
const zs = `中行折算价:${$(this)
.find('td:nth-child(6)')
.text()}`;
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;
}
};
const info = {
title: name + ' ' + content,
title: formatTitle(),
description: content.replace(/\s/g, '<br>'),
pubDate: new Date(date).toUTCString(),
guid: name + date,