feat: 添加雪球組合調倉信息 (#2568)
* Add xueqiu snb * Fix an error in doc * fix write style * Fix code style
This commit is contained in:
@@ -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'));
|
||||
|
||||
@@ -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],
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user