From 0e952af6f04afa9e4b74286ef8563f6c45e4fb80 Mon Sep 17 00:00:00 2001 From: linbuxiao <56839018+linbuxiao@users.noreply.github.com> Date: Sat, 27 Nov 2021 15:57:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(router):=20cebbank=20=E5=85=89=E5=A4=A7?= =?UTF-8?q?=E9=93=B6=E8=A1=8C=20(#8293)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/other.md | 18 +++++++ lib/v2/cebbank/all.js | 48 +++++++++++++++++ lib/v2/cebbank/history.js | 49 +++++++++++++++++ lib/v2/cebbank/maintainer.js | 4 ++ lib/v2/cebbank/radar.js | 19 +++++++ lib/v2/cebbank/router.js | 4 ++ lib/v2/cebbank/templates/allDes.art | 2 + lib/v2/cebbank/templates/historyDes.art | 3 ++ lib/v2/cebbank/utils.js | 70 +++++++++++++++++++++++++ 9 files changed, 217 insertions(+) create mode 100644 lib/v2/cebbank/all.js create mode 100644 lib/v2/cebbank/history.js create mode 100644 lib/v2/cebbank/maintainer.js create mode 100644 lib/v2/cebbank/radar.js create mode 100644 lib/v2/cebbank/router.js create mode 100644 lib/v2/cebbank/templates/allDes.art create mode 100644 lib/v2/cebbank/templates/historyDes.art create mode 100644 lib/v2/cebbank/utils.js diff --git a/docs/other.md b/docs/other.md index dd44c98f9..7223ae7f0 100644 --- a/docs/other.md +++ b/docs/other.md @@ -996,6 +996,24 @@ type 为 all 时,category 参数不支持 cost 和 free +## 光大银行 + +### 外汇牌价 + +#### 总览 + + + +#### 历史牌价 + + + +| 美元 | 英镑 | 港币 | 瑞士法郎 | 瑞典克郎 | 丹麦克郎 | 挪威克郎 | 日元 | 加拿大元 | 澳大利亚元 | 新加坡元 | 欧元 | 澳门元 | 泰国铢 | 新西兰元 | 韩圆 | +|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----| +| usd | gbp | hkd | chf | sek | dkk | nok | jpy | cad | aud | sgd | eur | mop | thb | nzd | krw | + + + ## 中国邮政速递物流 ### 新闻 diff --git a/lib/v2/cebbank/all.js b/lib/v2/cebbank/all.js new file mode 100644 index 000000000..fd4075631 --- /dev/null +++ b/lib/v2/cebbank/all.js @@ -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, + }; +}; diff --git a/lib/v2/cebbank/history.js b/lib/v2/cebbank/history.js new file mode 100644 index 000000000..7bf7bd187 --- /dev/null +++ b/lib/v2/cebbank/history.js @@ -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}¤tPagebak=1¤tPage=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, + }; +}; diff --git a/lib/v2/cebbank/maintainer.js b/lib/v2/cebbank/maintainer.js new file mode 100644 index 000000000..64a3fea19 --- /dev/null +++ b/lib/v2/cebbank/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/quotation/all': ['linbuxiao'], + '/quotation/history/:type': ['linbuxiao'], +}; diff --git a/lib/v2/cebbank/radar.js b/lib/v2/cebbank/radar.js new file mode 100644 index 000000000..4266231bb --- /dev/null +++ b/lib/v2/cebbank/radar.js @@ -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}`, + }, + ], + }, +}; diff --git a/lib/v2/cebbank/router.js b/lib/v2/cebbank/router.js new file mode 100644 index 000000000..6abd69969 --- /dev/null +++ b/lib/v2/cebbank/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/quotation/all', require('./all')); + router.get('/quotation/history/:type', require('./history')); +}; diff --git a/lib/v2/cebbank/templates/allDes.art b/lib/v2/cebbank/templates/allDes.art new file mode 100644 index 000000000..4df396626 --- /dev/null +++ b/lib/v2/cebbank/templates/allDes.art @@ -0,0 +1,2 @@ +

购汇:{{ fcer }},购钞:{{ pmc }}

+

结汇: {{ exrt }},结钞:{{ mc }}

\ No newline at end of file diff --git a/lib/v2/cebbank/templates/historyDes.art b/lib/v2/cebbank/templates/historyDes.art new file mode 100644 index 000000000..e6c5697b6 --- /dev/null +++ b/lib/v2/cebbank/templates/historyDes.art @@ -0,0 +1,3 @@ +

更新时间: {{ time }} +

购汇:{{ fcer }},购钞:{{ pmc }}

+

结汇: {{ exrt }},结钞:{{ mc }}

\ No newline at end of file diff --git a/lib/v2/cebbank/utils.js b/lib/v2/cebbank/utils.js new file mode 100644 index 000000000..0d2b8a13f --- /dev/null +++ b/lib/v2/cebbank/utils.js @@ -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, +};