* 雪球基金净值更新调整为蛋卷基金 * Update docs/finance.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update docs/finance.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * refactor: migrate to v2 * fix: parseDate * fix: fund unnecessary String() * feat: add radar * fix: stock comments template * style: add a linebreak * docs: fund example path
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
const got = require('@/utils/got');
|
||
const { parseDate } = require('@/utils/parse-date');
|
||
|
||
module.exports = async (ctx) => {
|
||
const id = ctx.params.id;
|
||
const url = 'https://xueqiu.com/p/' + id;
|
||
|
||
const response = await got({
|
||
method: 'get',
|
||
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 time = obj.sell_rebalancing.updated_at;
|
||
|
||
const single = {
|
||
title,
|
||
description,
|
||
pubDate: parseDate(time),
|
||
link: url,
|
||
guid: `xueqiu::snb::${id}::${time}`,
|
||
};
|
||
|
||
ctx.state.data = {
|
||
title: snb_title,
|
||
link: url,
|
||
description: snb_description,
|
||
item: [single],
|
||
};
|
||
};
|