Skip to content

Commit

Permalink
feat: 中国银行外汇牌价 多格式标题支持 (#2152)
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryQW authored and DIYgod committed May 17, 2019
1 parent 2e9b312 commit b3c93b8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
11 changes: 8 additions & 3 deletions docs/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

## 移动支付网

Expand All @@ -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>

## 自如

Expand Down
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
49 changes: 43 additions & 6 deletions lib/routes/boc/whpj.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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,
Expand Down

0 comments on commit b3c93b8

Please sign in to comment.