feat: 添加雪球組合調倉信息 (#2568)

* Add xueqiu snb

* Fix an error in doc

* fix write style

* Fix code style
This commit is contained in:
Zhang Zhishan
2019-07-07 20:29:00 +08:00
committed by DIYgod
parent 6668fe10e3
commit c87b63dfa8
3 changed files with 45 additions and 0 deletions

View File

@@ -716,6 +716,10 @@ pageClass: routes
<Route author="HenryQW" example="/xueqiu/fund/040008" path="/xueqiu/fund/:id" :paramsDesc="['基金代码, 可在基金主页 URL 中找到. 此路由的数据为场外基金 (`F`开头)']"/>
### 组合最新调仓信息
<Route author="ZhishanZhang" example="/xueqiu/p/ZH1288184" path="/xueqiu/snb/:id" :paramsDesc="['组合代码, 可在组合主页 URL 中找到.']"/>
### 股票信息
<Route author="YuYang" example="/xueqiu/stock_info/SZ000002" path="/xueqiu/stock_info/:id/:type?" :paramsDesc="['股票代码(需要带上交易所)', '动态的类型, 不填则为股票公告']">

View File

@@ -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'));

40
lib/routes/xueqiu/snb.js Normal file
View File

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