forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): cib/whpj (DIYgod#14539)
* feat(route): cib/whpj 兴业银行外汇牌价 * fix lint & security issue * fix code review
- Loading branch information
1 parent
a0f571f
commit 774f8c9
Showing
7 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/whpj/:format?': ['Qixingchen'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
'cib.com.cn': { | ||
_name: '中国兴业银行', | ||
'.': [ | ||
{ | ||
title: '外汇牌价', | ||
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-xing-ye-yin-hang', | ||
source: ['/'], | ||
target: '/cib/whpj', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = (router) => { | ||
router.get('/whpj/:format?', require('./whpj')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const https = require('https'); | ||
const crypto = require('crypto'); | ||
const config = require('@/config').value; | ||
|
||
module.exports = async (ctx) => { | ||
// fix unsafe legacy renegotiation disabled | ||
const agent = new https.Agent({ | ||
secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT, | ||
}); | ||
|
||
const response = await got('https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery.do', { agent: { https: agent } }); | ||
const cookies = response.headers['set-cookie'].map((item) => item.split(';')[0]).join(';'); | ||
|
||
const $ = cheerio.load(response.data); | ||
let date = $('div.main-body').find('div.labe_text').text(); | ||
date = date.split('\n\t')[1].replace('日期:', '').trim(); | ||
date = date.substring(0, 11) + date.substring(15); | ||
|
||
const link = 'https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery/list?_search=false&dataSet.rows=80&dataSet.page=1&dataSet.sidx=&dataSet.sord=asc'; | ||
const data = await ctx.cache.tryGet( | ||
link, | ||
async () => { | ||
const detailResponse = await got(link, { | ||
headers: { | ||
Cookie: cookies, | ||
}, | ||
agent: { https: agent }, | ||
}); | ||
return detailResponse.data; | ||
}, | ||
config.cache.contentExpire, | ||
false | ||
); | ||
|
||
const format = ctx.params.format; | ||
|
||
ctx.state.data = { | ||
title: '中国兴业银行外汇牌价', | ||
link: 'https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery.do', | ||
item: data.rows.map((item) => { | ||
const name = `${item.cell[0]} ${item.cell[1]}`; | ||
|
||
const xhmr = `现汇买入价:${item.cell[3]}`; | ||
|
||
const xcmr = `现钞买入价:${item.cell[5]}`; | ||
|
||
const xhmc = `现汇卖出价:${item.cell[4]}`; | ||
|
||
const xcmc = `现钞卖出价:${item.cell[6]}`; | ||
|
||
const content = `${xhmr} ${xcmr} ${xhmc} ${xcmc}`; | ||
|
||
return { | ||
title: formatTitle(name, xhmr, xcmr, xhmc, xcmc, content, format), | ||
pubDate: parseDate(date, 'YYYY年MM月DD日 HH:mm:ss'), | ||
description: content.replaceAll(/\s/g, '<br>'), | ||
guid: `${item.cell[0]} ${item.cell[1]} ${date}`, | ||
}; | ||
}), | ||
}; | ||
}; | ||
|
||
function formatTitle(name, xhmr, xcmr, xhmc, xcmc, content, format) { | ||
switch (format) { | ||
case 'short': | ||
return name; | ||
case 'xh': | ||
return `${name} ${xhmr} ${xhmc}`; | ||
case 'xc': | ||
return `${name} ${xcmr} ${xcmc}`; | ||
case 'xhmr': | ||
return `${name} ${xhmr}`; | ||
case 'xhmc': | ||
return `${name} ${xhmc}`; | ||
case 'xcmr': | ||
return `${name} ${xcmr}`; | ||
case 'xcmc': | ||
return `${name} ${xcmc}`; | ||
default: | ||
return `${name} ${content}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters