From b3c93b8ba8f7aceeb6f8c85fdf94ea4ed800d11b Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Fri, 17 May 2019 03:51:49 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=AD=E5=9B=BD=E9=93=B6=E8=A1=8C?= =?UTF-8?q?=E5=A4=96=E6=B1=87=E7=89=8C=E4=BB=B7=20=E5=A4=9A=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=A0=87=E9=A2=98=E6=94=AF=E6=8C=81=20(#2152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/other.md | 11 +++++++--- lib/router.js | 2 +- lib/routes/boc/whpj.js | 49 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/docs/other.md b/docs/other.md index 68f0ff7542..5f40344986 100644 --- a/docs/other.md +++ b/docs/other.md @@ -791,8 +791,7 @@ type 为 all 时,category 参数不支持 cost 和 free ### 首页 - - + ## 移动支付网 @@ -816,7 +815,13 @@ type 为 all 时,category 参数不支持 cost 和 free ### 中国银行外汇牌价 - + + +| 短格式 | 中行折算价 | 现汇买卖 | 现钞买卖 | 现汇买入 | 现汇卖出 | 现钞买入 | 现钞卖出 | +| ------ | ---------- | -------- | -------- | -------- | -------- | -------- | -------- | +| short | zs | xh | xc | xhmr | xhmc | xcmr | xcmc | + + ## 自如 diff --git a/lib/router.js b/lib/router.js index 3c1b8169fc..f67b2ae6a0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/boc/whpj.js b/lib/routes/boc/whpj.js index 9691c0a1c4..bca1dc2516 100644 --- a/lib/routes/boc/whpj.js +++ b/lib/routes/boc/whpj.js @@ -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, '
'), pubDate: new Date(date).toUTCString(), guid: name + date,