Files
RSSHub/lib/v2/xueqiu/snb.js
T
大象鼻子长又长andTony 840cfebc4e fix(route): xueqiu snb.js (#10281)
* Update snb.js

* fix: use random ua

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2022-07-31 04:24:56 +08:00

46 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const UA = require('@/utils/rand-user-agent')({ browser: 'chrome', os: 'android', device: 'mobile' });
module.exports = async (ctx) => {
const id = ctx.params.id;
const url = 'https://xueqiu.com/p/' + id;
const response = await got(url, {
headers: {
'User-Agent': UA,
},
});
const data = response.data;
const pattern = /SNB.cubeInfo = {(.+)}/;
const info = pattern.exec(data);
const obj = JSON.parse('{' + info[1] + '}');
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],
};
};