From c87b63dfa8f4dbadb8a9e577cbd88b3722a0ec01 Mon Sep 17 00:00:00 2001 From: Zhang Zhishan Date: Sun, 7 Jul 2019 20:29:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=9B=AA=E7=90=83?= =?UTF-8?q?=E7=B5=84=E5=90=88=E8=AA=BF=E5=80=89=E4=BF=A1=E6=81=AF=20(#2568?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add xueqiu snb * Fix an error in doc * fix write style * Fix code style --- docs/social-media.md | 4 ++++ lib/router.js | 1 + lib/routes/xueqiu/snb.js | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 lib/routes/xueqiu/snb.js diff --git a/docs/social-media.md b/docs/social-media.md index e826edc949..61425b1b8b 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -716,6 +716,10 @@ pageClass: routes +### 组合最新调仓信息 + + + ### 股票信息 diff --git a/lib/router.js b/lib/router.js index 30b598ec6a..f35d91d3f1 100644 --- a/lib/router.js +++ b/lib/router.js @@ -410,6 +410,7 @@ router.get('/xueqiu/favorite/:id', require('./routes/xueqiu/favorite')); router.get('/xueqiu/user_stock/:id', require('./routes/xueqiu/user_stock')); router.get('/xueqiu/fund/:id', require('./routes/xueqiu/fund')); router.get('/xueqiu/stock_info/:id/:type?', require('./routes/xueqiu/stock_info')); +router.get('/xueqiu/snb/:id', require('./routes/xueqiu/snb')); // Greasy Fork router.get('/greasyfork/:language/:domain?', require('./routes/greasyfork/scripts')); diff --git a/lib/routes/xueqiu/snb.js b/lib/routes/xueqiu/snb.js new file mode 100644 index 0000000000..f87bb1aac1 --- /dev/null +++ b/lib/routes/xueqiu/snb.js @@ -0,0 +1,40 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const url = 'https://xueqiu.com/p/' + id; + + const response = await got({ + method: 'get', + url: url, + }); + + const data = response.data; + const pattern = /SNB.cubeInfo = (.+?);/; + const info = pattern.exec(data)[1]; + const obj = JSON.parse(info); + const rebalancing_histories = obj.sell_rebalancing.rebalancing_histories; + const snb_title = obj.name + ' 的调仓历史'; + const snb_description = obj.description; + + const title = obj.name + ' 的上一笔调仓'; + let description = ''; + for (const some_detail of rebalancing_histories) { + const prev_weight_adjusted = some_detail.prev_weight_adjusted ? some_detail.prev_weight_adjusted : 0; + description += some_detail.stock_name + ' from ' + prev_weight_adjusted + ' to ' + some_detail.target_weight + ',\n'; + } + + const single = { + title, + description, + pubDate: new Date().toUTCString(), + link: url, + }; + + ctx.state.data = { + title: snb_title, + link: url, + description: snb_description, + item: [single], + }; +};