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], + }; +};